Game Development Community

Cube map loading...

by Chris \"Hobbiticus\" Weiland · in Torque Game Engine · 03/01/2003 (4:49 pm) · 12 replies

After about 5 hours of coding/hacking and 2 hours of reinstalling windows and realizing that I hadn't backed up my work, then another hour of coding to get my work back, I finally completed cube map loading in torque.

Currently, I can say mCubeMap = TextureHandle(NULL, CubeTexture); to generate a normalization cube map in code. I can also say mCubeMap = TextureHandle(mCubeMapName, CubeTexture); to load a cube map from file. You give it a "base" name of something like "fps/data/terrains/details/cube" and it loads "fps/data/terrains/details/cube_posx" and cube_negx, cube_posy, and so on for all 6 faces.

I had to do this for the big graphical enhancements I've been working on, but idk if anyone else wants to use cube maps for anything they want to do.

I just wanted to know if anyone else needed to use these cube maps for any graphical enhancements they were planning on doing. If there are a good number of people who want it, I'll go ahead an submit it as a resource. Otherwise, just contact me and I'll see what I can do.

Note for people who do not know much about cube maps: Adding cube map loading to your version of torque will do ABSOLUTELY NOTHING to the renderer or make the graphics any better unless you code in uses for them. Using cube maps usually involves fairly high level rendering techniques such as dot3 bump mapping, pixel shading, vertex shading, and fragment programs. So, if you want it just so it will make your game look better, don't bother getting it unless you know how to apply them.

Now that I got this done, it's time to go learn scary Cg.... /me is scared...

#1
03/01/2003 (5:07 pm)
sounds very cool and i can see how it is progress towards implementing shaders. I bump map every damn texture and skin i do...
#2
03/01/2003 (5:39 pm)
Hmmph. I just spent about 5 minutes cutting and pasting out of a sample from ATI's developer's site, but different strokes for different folks, I guess...
#3
03/01/2003 (6:03 pm)
mark you are utterly useless.

-brad
#4
03/01/2003 (6:16 pm)
Just pointing out in my own little way that people who need cubemaps probably can find other references on them fairly quickly.
#5
03/01/2003 (7:37 pm)
=D
#6
03/01/2003 (9:53 pm)
@Tim - yeah, it is, actually. Which is kinda scary since I just started opengl programming about 2 years ago. I hope I'm not getting myself in too deep :\

@Mark - yeah, it's not that hard to find resources on cube maps, but actually getting them to load in torque is a HUGE pain because of the structure of gTexManager.cc. Look at it sometime, and run away scared :)

So, whoever wants it, I'm on #garagegames on irc.maxgaming.net all the time - just pm me to get the source. If enough people want it, i'll post as a resource. Just keep in mind that you shouldn't get it unless you know how to apply it, or else it's utterly useless and just bloats your code.
#7
03/02/2003 (7:00 am)
Well, It literally took my 5 mintues to add my own cubemaps, but admittedly I didn't do it through the texManager. ;)
#8
03/02/2003 (8:18 am)
Well Mark, so how did you do it?
#9
03/02/2003 (8:37 am)
Well, same as everyone else, I imagine:

glGenTextures(1, &cubemapID);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubemapID);
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
	glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, 
		GL_NEAREST);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapPX);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapPY);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapPZ);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapNX);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapNY);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, 3, 
		CUBEMAP_TEX_SIZE, CUBEMAP_TEX_SIZE, 0, GL_RGB,
		GL_UNSIGNED_BYTE, cubemapNZ);

etc, etc...

I didn't use the texManager because I'm dynamically generating them anyways.
#10
03/02/2003 (10:00 am)
Yes, the texture manager is a beast that would make the likes of Hercules run away like a little girl. Dynamic Cube mapping is absolutly beautiful, but what a performance hog. You don't have to update the cube map every frame, every other frame works fine unless you are going really really fast.
#11
03/02/2003 (4:14 pm)
making your cube map that way also leads to
a) incompatibility with other texture options (i.e. can't have global texture options that affect the cube map)
b) code duplication
c) possible performance loss

It's best to go through gTexManager so that you don't encounter such adverse effects.
#12
03/02/2003 (4:24 pm)
Trust me Chris, for my application, I definately did _not_ want to use the texture manager.

If anyone out there is using static cubemaps (Like, I dunno, static environment maps maybe?) they would be advised to use the texture manager.