Advertisement Jump to content
Sign in to follow this  
honigkuchen

OpenGL problems with texturing a cube (on every side another texture)

This topic is 4903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i want to bind 6 textures on a cube, there should be on every side of the cube another image. my textures have a 128px width and height and are in the .rgb format. to test it I just bound a texture just on the front side of the cube. that worked fine. in the next step I tried to bind another texture to the front. but the same texture appears in the back as it appears in the front, and I don't really know why. maybe someone can help me? following some parts of the source code: loading the textures in the init() texture[0]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_1.rgb"); texture[1]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_2.rgb"); texture[2]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_3.rgb"); texture[3]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_4.rgb"); texture[4]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_5.rgb"); texture[5]=gltxReadRGB("/Users/sandi/projekte/opengl/puzzle_050820/1_6.rgb"); glGenTextures(2, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); 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, texture[0]->components, texture[0]->width, texture[0]->height, 0, GL_RGB, GL_UNSIGNED_BYTE,texture[0]->data); glBindTexture(GL_TEXTURE_2D, texName[1]); 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, texture[1]->components, texture[1]->width, texture[1]->height, 0, GL_RGB, GL_UNSIGNED_BYTE,texture[1]->data); glEnable(GL_TEXTURE_2D); in my drawThisCubes() function I bind the textures like this: /* front - 1 */ if (cubeMatrix[drawThisCube][3] == 1){ glBindTexture(GL_TEXTURE_2D, texName[0]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); // GL_BLEND or GL_DECAL or GL_REPLACE glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f,-0.5f, 0.5f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.5f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f); glEnd(); } if (cubeMatrix[drawThisCube][4] == 1) { glBindTexture(GL_TEXTURE_2D, texName[1]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f,-0.5f,-0.5f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f,-0.5f,-0.5f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f,-0.5f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, 0.5f,-0.5f); glEnd(); } can anybody recognize where the problem is? many thanks in advance. honigkuchen

Share this post


Link to post
Share on other sites
Advertisement
it's me again. I try to solve the problems since two days, right after I posted the above question I found the problem.

as the cube can be rotated, I check every position. I bound the second texture in the if-statement where the cube is rotated for 180 deg around the x-axis (where the back is now in the front) and NOT where the back is in the back.

sorry to bother you with such a silly question. bye honigkuchen

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!