Archived

This topic is now archived and is closed to further replies.

Anyone know how to cube-map?

This topic is 5110 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 have been looking all over the net for a cube-mapping tutorial, and all I have found are Developer demos using extensions, slide shows (?) that don''t help, and un-commented example source code in GLUT and DirectX. Does anyone know how to or can refer me to a good site? Maybe when I''m done I should write the ONLY TUTORIAL ABOUT IT ON THE NET! Pleeeze help.

Share this post


Link to post
Share on other sites
The only way I have seen cubemapping done is with an extension. Here''s some source code from NitroGLs code. You can go to his website at http://www.nitrogl.cjb.net

  // Uploads six images as a cube map

unsigned int TGA_UploadCube(char *right, char *left, char *top, char *bottom, char *front, char *back)
{
unsigned int TextureID;
TGA_t TGA_right, TGA_left, TGA_top, TGA_bottom, TGA_front, TGA_back;

if(!TGA_GetData(right, &TGA_right))
{
free(TGA_right.Data);
return 0;
}

if(!TGA_GetData(left, &TGA_left))
{
free(TGA_left.Data);
return 0;
}

if(!TGA_GetData(top, &TGA_top))
{
free(TGA_top.Data);
return 0;
}

if(!TGA_GetData(bottom, &TGA_bottom))
{
free(TGA_bottom.Data);
return 0;
}

if(!TGA_GetData(front, &TGA_front))
{
free(TGA_front.Data);
return 0;
}

if(!TGA_GetData(back, &TGA_back))
{
free(TGA_back.Data);
return 0;
}

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &TextureID);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, TextureID);

if(!IsExtensionSupported("GL_EXT_texture_edge_clamp"))
{
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
else
{
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE_EXT);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE_EXT);
}

glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_RGB8, TGA_right.ImageSpec.Width, TGA_right.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_right.Data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL_RGB8, TGA_left.ImageSpec.Width, TGA_left.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_left.Data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL_RGB8, TGA_top.ImageSpec.Width, TGA_top.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_top.Data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL_RGB8, TGA_bottom.ImageSpec.Width, TGA_bottom.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_bottom.Data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL_RGB8, TGA_front.ImageSpec.Width, TGA_front.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_front.Data);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL_RGB8, TGA_back.ImageSpec.Width, TGA_back.ImageSpec.Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TGA_back.Data);

free(TGA_right.Data);
free(TGA_left.Data);
free(TGA_top.Data);
free(TGA_bottom.Data);
free(TGA_front.Data);
free(TGA_back.Data);

return TextureID;
}

Share this post


Link to post
Share on other sites
Thanks, I already got this answered from another post. I just got my real-time cube-mapped sphere into place, and now I just need a little more tinkering to make it work! I am excited- this is a neat effect and doesn''t run too slowly on my machine. Thanks to all (this post and others) that helped me.

Share this post


Link to post
Share on other sites
Thanks, I already got this answered from another post. I just got my real-time cube-mapped sphere into place, and now I just need a little more tinkering to make it work! I am excited- this is a neat effect and doesn''t run too slowly on my machine. Thanks to all (this post and others) that helped me.

Share this post


Link to post
Share on other sites
quote:
Original post by WhatEver
The only way I have seen cubemapping done is with an extension.


Is there no way to impliment cube mapping without extensions? My graphics card doesn''t support the cube mapping extension, but I really want to have this feature in my program.

Share this post


Link to post
Share on other sites
Sphere mapping should get the desired effect if your card doesn''t support cube mapping, although the quality isn''t quite as good. A quick google search turned up many results, including this Nehe tutorial:

http://nehe.gamedev.net/lesson.asp?index=05

Hope that helps.

----------------
Interesting quote deleted at request of owner

Share this post


Link to post
Share on other sites