PDA

View Full Version : Cube Texturing Problems



pvncheck
04-29-2011, 09:36 AM
Okay, I've done sooo much stuff for this assignment, but one thing keeps getting me. I have no idea how to do this:

Use OpenGL texture coordinate generation to "shrink-wrap" the earth GL_RGBA texture onto the cube model.

Basically he's telling us to take one texture that looks like a Mercator projection of a map, and use that that to texture a cube. He wants us to wrap the whole cube in that one texture. I have no idea how to do this, and I've been trying for several hours to no avail. Is there any way to do this using glutSolidCube(), or do I need to do something else. Any help would be appreciated. I would post code, but I don't know which part of it isn't working and it's spread over 300 lines, so it would probably hurt more to post the code than to ask for a method to do this. Thank you for your time.



void clamp_cube(GSTATE *gs){
glColor3f ( a_col,b_col,c_col );



// setup texture mapping

//glEnable( GL_TEXTURE_2D );



glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, gs->mat_amb);

glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gs->mat_diff);

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gs->mat_spec);

glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, gs->mat_shininess);

glActiveTextureARB(GL_TEXTURE0);

glBindTexture(GL_TEXTURE_2D, texture[2]);

glBegin(GL_QUADS);

// Front Face

//glNormal3f(-1.0f, -1.0f, 1.0f);
glNormal3f(0,0,1);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);

//glNormal3f(1.0f, -1.0f, 1.0f);
glNormal3f(0,0,1);glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);

//glNormal3f(1.0f, 1.0f, 1.0f);
glNormal3f(0,0,1);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);

//glNormal3f(-1.0f, 1.0f, 1.0f);
glNormal3f(0,0,1);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

// Back Face



//glNormal3f(-1.0f, -1.0f, -1.0f);
glNormal3f(0,0,-1);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);

//glNormal3f(-1.0f, 1.0f, -1.0f);

glNormal3f(0,0,-1);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);

//glNormal3f(1.0f, 1.0f, -1.0f);

glNormal3f(0,0,-1);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);

//glNormal3f( 1.0f, -1.0f, -1.0f);

glNormal3f(0,0,-1);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);



// Top Face

//glNormal3f(-1.0f, 1.0f, -1.0f);

glNormal3f(0,1,0);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);

//glNormal3f(-1.0f, 1.0f, 1.0f);

glNormal3f(0,1,0);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

//glNormal3f( 1.0f, 1.0f, 1.0f);

glNormal3f(0,1,0);glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);

//glNormal3f( 1.0f, 1.0f, -1.0f);

glNormal3f(0,1,0);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);



// Bottom Face

//glNormal3f(-1.0f, -1.0f, -1.0f);

glNormal3f(0,-1,0);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);

//glNormal3f(1.0f, -1.0f, -1.0f);

glNormal3f(0,-1,0);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);

//glNormal3f(1.0f, -1.0f, 1.0f);

glNormal3f(0,-1,0);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);

//glNormal3f(-1.0f, -1.0f, 1.0f);

glNormal3f(0,-1,0);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);



// Right face

//glNormal3f(1.0f, -1.0f, -1.0f);

glNormal3f(1,0,0);glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);

//glNormal3f(1.0f, 1.0f, -1.0f);

glNormal3f(1,0,0);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);

//glNormal3f(1.0f, 1.0f, 1.0f);

glNormal3f(1,0,0);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);

//glNormal3f(1.0f, -1.0f, 1.0f);

glNormal3f(1,0,0);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);



// Left Face

//glNormal3f(-1.0f, -1.0f, -1.0f);

glNormal3f(-1,0,0);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);

//glNormal3f(-1.0f, -1.0f, 1.0f);

glNormal3f(-1,0,0);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);

//glNormal3f(-1.0f, 1.0f, 1.0f);

glNormal3f(-1,0,0);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);

//glNormal3f(-1.0f, 1.0f, -1.0f);

glNormal3f(-1,0,0);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);



glEnd();
}



My apologies for the commented out normals, I'm reusing some code from another part of the assignment. Anyway, this produces a cube with the texture placed on each face, is there any way to just get the one texture to wrap all the way around, as if the cube were a sphere?

BionicBytes
04-29-2011, 01:13 PM
You could try the glTexGen command to generate texture coords for you. However using a shader is far easier and makes this sort of thing trivial