简体   繁体   中英

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

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)

  • numer of components
  • arrangement of components
  • size of each component

(parameters to glPixelStore)

  • alignment (0 for tight packing, otherwise alignment to 1, 2 or 4 bytes)
  • pixel and row run lenghts (usually those are 0)

Please see the documentation of glTexImage and glPixelStore and set them apropriately for your image data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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