Jump to content
  • Advertisement
Sign in to follow this  
knobby67

help with enviroment cube mapping

This topic is 3900 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

Hello:) I'm trying to learn how to do cube mapping for reflections on objects. The problem is all I see is an unmapped polygon. I load in 6 maps, they are working because if I comment out the cube map enable code the cube is mapped with the last image loaded. This is the code I copied from the net to view a cube map, is it correct?

		glLoadIdentity();
		glTranslatef(xpos,ypos,zpos);
		rot+=0.01f;
		glRotatef(rot,0.0f,1.0f,0.0f);
		glRotatef(rot,1.0f,0.0f,0.0f);
		glRotatef(rot,0.0f,0.0f,1.0f);



   glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X, xpositive.texture_id);
   glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, xnegitive.texture_id);
   glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, ypositive.texture_id);
   glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, ynegitive.texture_id);
   glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, zpositive.texture_id);
   glBindTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, znegitive.texture_id);

   glEnable(GL_TEXTURE_CUBE_MAP);

   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);

   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glEnable(GL_TEXTURE_GEN_R);



glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();


 glDisable(GL_TEXTURE_GEN_S);
 glDisable(GL_TEXTURE_GEN_T);
 glDisable(GL_TEXTURE_GEN_R);


glDisable(GL_TEXTURE_CUBE_MAP);

[\source]

The images are loaded it's just the cube shows nothing when I try to enable the cube map flags, does anything else need set? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
It's illegal to call
glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X, xpositive.texture_id);

you need to call
glBindTexture(GL_TEXTURE_CUBE_MAP, texture_id);

in order to bind 1 single cubemap.
PS : call glGetError to check for errors.

Share this post


Link to post
Share on other sites
I'm unsure why that's illegal, I have 6 texture structures which hold my texture data, texture.id is just the GLuint holding the texture number.

Share this post


Link to post
Share on other sites
It illegal because GL only accepts GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D or GL_TEXTURE_CUBE_MAP. You seem to think you need to bind the different faces but that's not how cubemaps work.

call
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture_id);
and then define the 6 faces of the cubemap.

Share this post


Link to post
Share on other sites
To define the six faces, you need to do something along these lines.


// bind the cubemap texture
glBindTexture(GL_TEXTURE_CUBE_MAP, m_nCubeMapTexture);

// generate no mipmaps
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_FALSE);

// send the temp image to the card
for (int i = 0; i < CM_MAX_TYPES; i++)
{
// send the image to the graphics card
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0,
GL_RGBA8,
m_nDynCubemapSize,
m_nDynCubemapSize,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
NULL);
}

// setup the cube map texture parameters
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!