简体   繁体   English

在openGL中用2D纹理映射3D对象

[英]Texture Mapping a 3D object with a 2D texture in openGL

I have a cube that is made of triangles, so 8 vertices and corresponding incides to create the triangle. 我有一个由三角形组成的立方体,所以有8个顶点和相应的斜率来创建三角形。 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. 我看到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. 我了解到,由于图像可能小于实际对象,因此没有必要的一对一对应关系,因此我尝试将amt设置为较小的值,但仍然不可行。

For regular textures that sampling range in each coordinate is 0 to 1, independent of the sampling resolution. 对于常规纹理,每个坐标中的采样范围是0到1,与采样分辨率无关。

Unfortunately your code is absolutely non-telling, it could be anything. 不幸的是,您的代码绝对是不讲故事的,可以是任何东西。 We really need to see more of it, especially the actual OpenGL calls. 我们确实需要查看更多信息,尤其是实际的OpenGL调用。

EDIT due to comment 由于评论而编辑

Loading image data one must tell OpenGL the layout of the data in the buffer. 加载图像数据必须告诉OpenGL缓冲区中数据的布局。 The essential information are 基本信息是

(parameters to glTexImage) (glTexImage的参数)

  • numer of components 零件数量
  • arrangement of components 组件排列
  • size of each component 每个组件的大小

(parameters to glPixelStore) (glPixelStore的参数)

  • alignment (0 for tight packing, otherwise alignment to 1, 2 or 4 bytes) 对齐(0表示紧密打包,否则对齐1、2或4个字节)
  • pixel and row run lenghts (usually those are 0) 像素和行的长度(通常为0)

Please see the documentation of glTexImage and glPixelStore and set them apropriately for your image data. 请参阅glTexImageglPixelStore的文档,并为您的图像数据进行适当设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM