Archived

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

hooded_paladin

Anyone know how to cube-map?

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
try http://nehe.gamedev.net
great site for both beginners and more advanced programmers. look in the tutorials section and you''ll find one that teaches you how to map textures onto a cube

Share this post


Link to post
Share on other sites
No, not the same thing. That is texture-mapping, I know that! Cube mapping is a way of doing reflections (among other things) by specifying six views and using them to draw reflections on a mirrored object, like a sphere. Sorry, wrong idea.

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
Dual paraboloid mapping sounds interesting, any idea where I could find more information about that? A quick seaarch on google didn''t turn up anything usefull.

Share this post


Link to post
Share on other sites
Here's some great info on cube mapping from nVidia:

http://www.nvidia.com/object/IO_20010830_4778.html

[edited by - MessageBox on December 15, 2003 3:11:33 PM]

Share this post


Link to post
Share on other sites