I am trying to map an image onto a NURBS surface. I have a 13×13 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 2×2 texture, I have 4 1×1 textures.
Where am I going wrong? And how can I fix it?
The texture has the coordinate range [0, 0] -> [1, 1]. Since the texture wrapping is set to
GL_REPEATby default, the coordinates used yield the 2×2 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: