Archived

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

Luke Miklos

cube mapping TROUBLE!!!!

Recommended Posts

Alright... I''ve looked online a TON & have ended up writing my cubemap code as stated below. The problem I''m having is that the sphere that I''m cube-mapping to is white, no matter what. Always white. Check it out... Oh ya... you''ll notice that I''m actually capturing 12 textures... 6 are just 2D textures so I could see display them on 6 polygons off the to side of the scene just to verify that I was rendering the 6 images correctly for the cube map. GLuint cmap; GLuint CUBE_TEXTURES[6]; //THIS IS IN THE INIT ROUTINE (ran once at start of program) q = gluNewQuadric(); gluQuadricNormals(q, GL_SMOOTH); gluQuadricOrientation(q,GLU_OUTSIDE); gluQuadricDrawStyle(q, GLU_FILL); gluQuadricTexture(q, GL_TRUE); glEnable(GL_NORMALIZE); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); //PARAMETER OPTION 1 glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER,GL_NEAREST); //TRIED GL_LINEAR too glGenTextures(1,&cmap); glGenTextures(6,&CUBE_TEXTURES[0]); //THIS IS WHERE WE RENDER THE SCENE 6 times & capture a texture //for each "camera view" (runs every frame) GLuint cube_directions[6] = {RIGHT,LEFT,UP,DOWN,BLACK,FLAT}; GLenum cube_faces[6]={ GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT }; for(i=0;i<6;i++) { glClearColor(0.0f, 0.0f, 0.0f, 0.5); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glViewport(0,0,cmap_width,cmap_height); //DRAW CRAP HERE glBindTexture(GL_TEXTURE_2D,CUBE_TEXTURES); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glReadPixels(0,0,cmap_width,cmap_height,GL_RGB, GL_UNSIGNED_BYTE,pixels); /*glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0,cmap_width,cmap_height, 0);*/ glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,cmap_width,cmap_height, 0,GL_RGB,GL_UNSIGNED_BYTE,pixels); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_CUBE_MAP_EXT); glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, cmap); /*glCopyTexImage2D(cube_faces[i], 0, GL_RGB, 0,0,cmap_width,cmap_height, 0);*/ glTexImage2D(cube_faces[i],0,GL_RGB,cmap_width,cmap_height, 0,GL_RGB,GL_UNSIGNED_BYTE,pixels); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_CUBE_MAP_EXT); } //END OF FOR LOOP //DRAW CUBE MAPPED OBJECT NOW.... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport( 0, 0, 640, 480 ); glColor4f(1.0f,1.0f,1.0f,0.5f); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glLoadIdentity(); glTranslatef(0.0f,0.0f,board_depth); glRotatef(rotate_x,1.0f,0.0f,0.0f); glTranslatef(0.0f,translate_y,0.0f); glTranslatef(ball_x,ball_y,ball_radius); glEnable(GL_TEXTURE_CUBE_MAP_EXT); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, cmap); gluSphere(q,ball_radius,64,64); glDisable(GL_TEXTURE_CUBE_MAP_EXT); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); ANY HELP???????????????????? PLEASE!!!!!!!!!!!!!!!!!!!!!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Never cube mapped before, but it appears to me you haven''t enabled 2d texturing. In the init, place

glEnable(GL_TEXTURE_2D) // Enable 2D texturing

somewhere. This is what I often forget. I can''t find it back in your opengl code either.

Julian

Share this post


Link to post
Share on other sites
It depends on how complex your reflected scene is. And also the resolution of the cubemap. In a fairly simple scene (heightmap terrain with about 500 particles) and a cubemap resolution of 256 x 256 pixels, I see no noticible drop in framerate.

I do have a GF4 4400 though.

Share this post


Link to post
Share on other sites
I don''t know the answer to all of those... however... I ran a cube map here at home on my wife''s KICKEN AWESOME comp & there is no difference in frame rate, whether you use:
glReadPixels() OR glCopyTexImage2D()

however... at my comp at work (shhhh) the glCopyTexImage2D() function works much quicker than the glReadPixels().

However... I need to do some operations on the images after I turn them into textures... because for some reason, the cube map used them upside down or inverted left to right. so all my reflections were upside down or backwards or BOTH!!!

anybody know a good way to invert a picture horizontally or vertically? perhaps with a function call? instead of having to step through the whole RGB array of bytes & swapping them??

ALSO.... when I render the scene from the SAME EXACT spot for all 6 faces of the cube, looking in all 6 different directions... the images don''t quite cover the whole scene, there is a gap that isn''t captured. does anybody know the angle of view that an opengl scene covers???? so I can do some TRIG & translate back into the scene for each of the 6 pictures???

Share this post


Link to post
Share on other sites
You need to make sure you''re using a 90 degree perspective. As for inverting your picture, just rotate the entire scene (relative to the camera) 180 degrees on the z-axis before you render it.

Share this post


Link to post
Share on other sites
Intamin,
I just looked up the info on gluPerspective() & that looks like exactly what I was missing. Great!!! I will be sure to try that out tonight. Thanks. I think I was just resetting the viewport before without resetting the perspective. :/ DUH.


Halibut,
I tried rotating the scene by 180 on the Z axis before rendering it & the reflections DO appear right side up... they just scroll the wrong way on my sphere, either left to right, or north to south. So it does look pretty good, but if you do a point check... you''ll notice that its geometrically incorrect. Any quick suggestions? Otherwise I''ll keep trying crap, & eventually I''ll run across the fix.

Luke

Share this post


Link to post
Share on other sites