重复纹理问题

发布于 2024-12-17 14:31:42 字数 1159 浏览 2 评论 0原文

我正在尝试将图像映射到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2024-12-24 14:31:42

纹理的坐标范围为 [0, 0] -> [1, 1]。由于默认情况下纹理环绕设置为 GL_REPEAT,因此使用的坐标会产生您观察到的 2x2 平铺。

编辑:

您需要缩放用于纹理坐标的 NURBS 曲面,或以其他方式缩放纹理坐标。后者可能不那么具有侵入性:

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. */

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. */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文