View Full Version : Texture mapping for NURBS

lily88

12-08-2005, 09:15 PM

I have found in msdn:

gluBeginSurface(nobj);

gluNurbsSurface(nobj, . . ., GL_MAP2_EXTURE_COORD_2);

gluNurbsSurface(nobj, . . ., GL_MAP2_VERTEX_4);

gluEndSurface(nobj);

but I am confused of hwo to determine the control points, and also the knots for the texture, are they the same with the NURBS drawn here? Thanks a lot.

The control points for the texture will be different than the control points for the texture. The texture control points are 2-dimensional and refer to the s,t texture coordinates. The knots for both should probably be the same. Here is a sample:

gluBeginSurface(theNurb);

gluNurbsSurface(theNurb,

// #knots = #control points + order of NURB - using linear

12, uknots, // number and knots in u dir

numvknots, vknots, //number and knots in v dir

80* 2, // u stride=#control points in v direction X size of data

2, //v stride

&texctlpoints[0][0][0], //texture coordinates

3,order, // order of u nurbs and v nurbs

GL_MAP2_TEXTURE_COORD_2);

gluNurbsSurface(theNurb,

12, uknots, // number and knots in u dir

numvknots, vknots, //number and knots in v dir

80 * 4, // u stride=#control points in v direction X size of data

4, //v stride

&ctlpoints[0][0][0], //control points

3,order, // order of u nurbs and v nurbs

GL_MAP2_VERTEX_4);

gluEndSurface(theNurb);

Go here for some additional sample code

http://www-1g.cs.luc.edu/~gm/comp53480/week13/nurbUtil.h

lily88

12-11-2005, 02:32 AM

Thank you so much gerry. I have read the sample, but because there is little comment and no definition of the variable 'sil' which is used to calculate both the control points of the nurbs and the texture, I am still confused how to find the control points for the texture from the control points for the nurbs. Can you give me a little more explanation? Thank you again.

Here is some more info:

http://www.rush3d.com/reference/opengl-redbook-1.1/chapter11.html

A simple example may make things a little clearer.

Suppose you have created a 3x2 array of object control points C(i,j). So you want to create a 3x2 array of texture control points. The texture control points are in texture space so they will probably be in the unit square [0,1] x [0,1],unless you want the texture to repeat. The simplest choice would be the uniformly placed points (0,0), (0.5,0), (1,0), (0,1), (0.5,1), (1,1). The problem with that is that the texture will be distorted if the distance between adjoining points in your object control grid is not uniform as well. One way to compensate for this is to use texture texture control points that are not uniformly distributed over [0,1] x [0,1]. Essentially you want to use the normalized distance between adjoining points in the object control grid to position points in the texture control grid. To do this in the 3x2 example, determine the distance between the control points in each column. Suppose that the distance between C(0,0) and C(1,0) is 2 and the distance between C(1,0) and C(2,0) is 6. The total length of this column is 8. Since the distance between C(0,0) and C(1,0) is 2,the normalized distance between them will be 2/8=0.25. So choose the first column of texture control points as (0,0), (0.25,0), (1,0). Now for the next column. Suppose that the distance from C(0,1) and C(1,1) is 8 and the distance between C(1,1) and C(2,1) is 2. Then the normalized distance between C(0,1) and C(1,1) is 0.8 and the second column of control points will be (0,1), (0.8,1), (1,1).

lily88

12-12-2005, 08:52 PM

problem solved, thanks a lot:)

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.