简体   繁体   中英

OpenGL multiple texture mapping on a cube using GLUT

Have been trying to figure out how to put a different texture on each side of a cube using OpenGL and GLUT. I can get it to be a simple texture but multiple texture won't. I would put up my code but it is ugly and cluttered right now. If this is pretty easy to do please post some code for me to follow. Thanks!

its NEHE openGL lesson #22 http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=22 , then if you want to have different texture for each face, you can modify the cube rendering part for each face by switching glClientActiveTextureARB(GL_TEXTURE0_ARB); ,or glClientActiveTextureARB(GL_TEXTURE1_ARB); depend on the number of texture you have.

for example: `

 // Back Face
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glNormal3f( 0.0f, 0.0f,-1.0f);
    for (i=4; i<8; i++) {
        glTexCoord2f(data[5*i],data[5*i+1]);
        glVertex3f(data[5*i+2],data[5*i+3],data[5*i+4]);
    }
    // Top Face  
    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glNormal3f( 0.0f, 1.0f, 0.0f);
    for (i=8; i<12; i++) {
        glTexCoord2f(data[5*i],data[5*i+1]);
        glVertex3f(data[5*i+2],data[5*i+3],data[5*i+4]);
    }

`

disclaimer: i never test those codes, its based on my memory, you should check ii'am in doubt whether it was glClientActiveTexture() or glActiveTexture()

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