重复纹理问题
我正在尝试将图像映射到 NURBS 曲面上。我有一个 13x13 的等距控制点数组,位于 (-1, -1), (-1, 1), (1, 1), (1, -1) 正方形中。我正在尝试使用以下代码将纹理映射到由控制点控制的 NURBS 曲面上:
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);
以下是我初始化程序所使用的参数:
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);
我面临的问题是我的纹理图像在周围重复 4 次原始即不是 2x2 纹理,我有 4 个 1x1 纹理。
我哪里出错了?我该如何解决它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
纹理的坐标范围为 [0, 0] -> [1, 1]。由于默认情况下纹理环绕设置为 GL_REPEAT,因此使用的坐标会产生您观察到的 2x2 平铺。
编辑:
您需要缩放用于纹理坐标的 NURBS 曲面,或以其他方式缩放纹理坐标。后者可能不那么具有侵入性:
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: