Question

I am trying to map an image onto a NURBS surface. I have a 13x13 array of equally spaced control points in a (-1, -1), (-1, 1), (1, 1), (1, -1) square. I am trying to map a texture onto the NURBS surface controlled by the control points using the following code:

gluNurbsSurface(nurbs_object,no_knots,&knots[0],no_knots,&knots[0],u_stride,v_stride,&ctr_points[0][0],u_order,v_order,GL_MAP2_TEXTURE_COORD_2);
gluNurbsSurface(nurbs_object,no_knots,&knots[0],no_knots,&knots[0],u_stride,v_stride,&ctr_points[0][0],u_order,v_order,GL_MAP2_VERTEX_3);
gluNurbsSurface(nurbs_object,no_knots,&knots[0],no_knots,&knots[0],u_stride,v_stride,&ctr_points[0][0],u_order,v_order,GL_MAP2_NORMAL);

The following are the parameters that I initialise my program with:

gluNurbsProperty(nurbs_object, GLU_SAMPLING_TOLERANCE, 50.0);
gluNurbsProperty(nurbs_object, GLU_DISPLAY_MODE, GLU_FILL);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_width, image_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

The problem I am facing is that I have the texture image repeating 4 times around the origin i.e. instead of a 2x2 texture, I have 4 1x1 textures.

Where am I going wrong? And how can I fix it?

Was it helpful?

Solution

The texture has the coordinate range [0, 0] -> [1, 1]. Since the texture wrapping is set to GL_REPEAT by default, the coordinates used yield the 2x2 tiling you observe.

EDIT:

You'll need to scale the NURBS surface used for the texture coordinates, or scale the texture coordinates some other way. The latter might be less intrusive:

GLint mmode;

glGetIntegerv(GL_MATRIX_MODE, & mmode); /* save active matrix stack. */
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glScalef(0.5, 0.5, 1.0);

/* ... draw ... */

glPopMatrix();
glMatrixMode((GLenum) mmode); /* restore active matrix stack. */
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top