在 openGL 中使用 2D 纹理映射 3D 对象
我有一个由三角形组成的立方体,因此有 8 个顶点和相应的内切来创建三角形。我在为这个立方体创建纹理坐标时遇到问题。我尝试使用如下值:
float amt = 1.0f;
m_texBuffer.push_back(Texel(0.0f, 0.0f));
m_texBuffer.push_back(Texel(amt, 0.0f));
m_texBuffer.push_back(Texel(amt, amt));
m_texBuffer.push_back(Texel(0.0f, amt));
m_texBuffer.push_back(Texel(0.0f, 0.0f));
m_texBuffer.push_back(Texel(amt, 0.0f));
m_texBuffer.push_back(Texel(amt, amt));
m_texBuffer.push_back(Texel(0.0f, amt));
随着 amt 值的变化,我得到了奇怪的视觉结果。我知道,由于图像可能比实际物体小,因此不存在一对一的对应关系,因此我尝试将 amt 设置为较小的值,但仍然不行。
I have a cube that is made of triangles, so 8 vertices and corresponding incides to create the triangle. Im having trouble creating the texture coordinates for this cube. I tried using values like:
float amt = 1.0f;
m_texBuffer.push_back(Texel(0.0f, 0.0f));
m_texBuffer.push_back(Texel(amt, 0.0f));
m_texBuffer.push_back(Texel(amt, amt));
m_texBuffer.push_back(Texel(0.0f, amt));
m_texBuffer.push_back(Texel(0.0f, 0.0f));
m_texBuffer.push_back(Texel(amt, 0.0f));
m_texBuffer.push_back(Texel(amt, amt));
m_texBuffer.push_back(Texel(0.0f, amt));
I get wierd visual results with varing values of amt. I understand that since an image can be smaller than the actual object that there is not nessaseraly a one to one correspondance so I tried to make amt a small value but still no go.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于常规纹理,每个坐标的采样范围为 0 到 1,与采样分辨率无关。
不幸的是,你的代码绝对不能说明问题,它可以是任何东西。我们确实需要了解更多内容,尤其是实际的 OpenGL 调用。
因评论而编辑
加载图像数据时必须告诉 OpenGL 缓冲区中数据的布局。基本信息是
(glTexImage 的参数)
(glPixelStore 的参数)
请参阅 glTexImage 和 glPixelStore并为您的图像数据适当地设置它们。
For regular textures that sampling range in each coordinate is 0 to 1, independent of the sampling resolution.
Unfortunately your code is absolutely non-telling, it could be anything. We really need to see more of it, especially the actual OpenGL calls.
EDIT due to comment
Loading image data one must tell OpenGL the layout of the data in the buffer. The essential information are
(parameters to glTexImage)
(parameters to glPixelStore)
Please see the documentation of glTexImage and glPixelStore and set them apropriately for your image data.