It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Gabe Kruger
Gamasutra
June 11, 1999

Letters to the Editor:
Write a letter
View all letters


Features

 

Contents

Introduction

On Lines

Connect the Curves

Rendering Bézier Curves

Divide and Conquer

Code Listing 2

Bézier Patches

Rendering Bézier Patches

Advanced Patching

Not All is Perfect

Advanced Patching

Right now, we have naked patches and would like to put some clothing on them. Applying a texture map to a patch is pretty straightforward. The simplest way is to parameterize the u and v coordinates for the texture using the s and t used to create the vertices. Listing 4 renders a texture mapped Bézier patch using this method. Constant steps along the parameter do not guarantee constant steps in arclength on the curve. This can lead to irregular texture stretching. This effect can be minimized by have the control points by fairly evenly spaced. To actually generate the texture coordinates using constant steps in arclength is pretty compute intensive and beyond the scope of this article, but it is possible.

Another feature of Bézier patches is the ability to dynamically modify the control points. This can simulate ripples in water, flags blowing in the breeze, bouncing body parts, and so on, while only manipulating a few control points.

Listing 4

/*

* This fragment takes the points returned by a function that subdivides a

* Bezier patch and renders them using triangle strips. Additionally, the

* triangles are texture mapped assuming the active texture maps directly to

* the patch.

*

* Point is an object that has the x, y, and z coordinates and defines

* some mathematical operations for points. See the project accompanying

* the article for its definition.

*

* LevelToWidth[] is a lookup table that calculates the widths of rows given

* the depth of recursion.

*

* cpoints is a 3 x 3 matrix of control points for the quadratic Bezier patch.

*/

glColor3f(0.0, 0.0, 1.0);

glEnable(GL_TEXTURE_2D);

Point* p = QuadraticBezierPatchSubdivide2(cpoints, 3);

int width = LevelToWidth[3];

// Step size along texture map

float step = 1.0 / (width - 1);

// For all the strips

for(int i = 0; i < width - 1; i++) {

// Texture coordinates

float x = 0.0;

float y = i * step;

// Emit the vertices on the strip incrementing the texture coordinates

glBegin(GL_TRIANGLE_STRIP);

for(int j = 0; j < width; j++) {

glTexCoord2f(x, y);

glVertex3f(p[i * width + j].x, p[i * width + j].y, p[i * width + j].z);

glTexCoord2f(x, y + step);

glVertex3f(p[(i + 1) * width + j].x, p[(i + 1) * width + j].y, p[(i + 1) * width + j].z);

x += step;

}

glEnd();

}

glDisable(GL_TEXTURE_2D);

// Free the points

delete[] p;


Not All is Perfect


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service