PDA

View Full Version : cube map



andreasMank
06-28-2004, 11:50 PM
i created a cube map .. now i want to draw a cube using this texture .. but i don't know how to set the coords ..


glMatrixMode(GL_MODELVIEW);
glDisable(GL_LIGHTING);
glPushMatrix();
glColor3f(1.0,1.0,1.0);

glBegin(GL_QUADS);

//unten
glNormal3f(0,-1,0);
glVertex3fv(m_bounding_box_vertex[0]);
glVertex3fv(m_bounding_box_vertex[1]);
glVertex3fv(m_bounding_box_vertex[5]);
glVertex3fv(m_bounding_box_vertex[4]);

//vorne
glNormal3f(0,0,1);
glVertex3fv(m_bounding_box_vertex[0]);
glVertex3fv(m_bounding_box_vertex[1]);
glVertex3fv(m_bounding_box_vertex[3]);
glVertex3fv(m_bounding_box_vertex[2]);

//links
glNormal3f(-1,0,0);
glVertex3fv(m_bounding_box_vertex[0]);
glVertex3fv(m_bounding_box_vertex[4]);
glVertex3fv(m_bounding_box_vertex[6]);
glVertex3fv(m_bounding_box_vertex[2]);

//rechts
glNormal3f(1,0,0);
glVertex3fv(m_bounding_box_vertex[1]);
glVertex3fv(m_bounding_box_vertex[5]);
glVertex3fv(m_bounding_box_vertex[7]);
glVertex3fv(m_bounding_box_vertex[3]);

//hinten
glNormal3f(0,0,-1);
glVertex3fv(m_bounding_box_vertex[4]);
glVertex3fv(m_bounding_box_vertex[5]);
glVertex3fv(m_bounding_box_vertex[7]);
glVertex3fv(m_bounding_box_vertex[6]);

//oben
glNormal3f(0,1,0);
glVertex3fv(m_bounding_box_vertex[2]);
glVertex3fv(m_bounding_box_vertex[3]);
glVertex3fv(m_bounding_box_vertex[7]);
glVertex3fv(m_bounding_box_vertex[6]);

glEnd();
glPopMatrix();
do i have to use glTexCoord3f .. or something like this ??

Jan
06-29-2004, 12:15 AM
Yes, you have to use glTexCoord3f.
Simply imagine, you were standing inside the cube. (0,0,0) is its center. (-1,1,-1) is the upper left front "vertex". (1,1,-1) is the upper right front "vertex". Et cetera.

Hope that helps you.

Jan.

vincoof
06-29-2004, 12:10 PM
Or you can use one of the useful texgens provided with cubemap functionality.
These are NORMAL_MAP_ARB and REFLECTION_MAP_ARB, the former mapping your vertex normal (glNormal) into the texture coordinate, and the latter mapping the reflection vector computed from the normal end the eye coordinate, a bit like SPHEREMAP but dedicated to cubemap lookup.