cube mapping TROUBLE!!!!
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, 0, GL_RGB,
0,0,cmap_width,cmap_height, 0);*/
glTexImage2D(cube_faces,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!!!!!!!!!!!!!!!!!!!!!!
</i>
Whatsoever you do, do it heartily as to the Lord, and not unto men.
Look at nutty''s dynamic cubemapping demo for some ideas : http://opengl.nutty.org
You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
November 16, 2003 12:28 PM
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
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
thanks guys, I checked out some more code online, especially that www.nutty site & I found my problem. I wasn''t binding to the cubemap texture BEFORE I set up all the cubemapping parameters. It works now!!!!!
Whatsoever you do, do it heartily as to the Lord, and not unto men.
How bad is the frame rate hit on that cube map? I have always avoided doing somthing like that because i figured it wasnt worth it.
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.
I do have a GF4 4400 though.
Another Q...
If i use GL_NORMAL_MAP_ARB as mode, does GL use the cube map as refraction map or as bump map??
If i use GL_NORMAL_MAP_ARB as mode, does GL use the cube map as refraction map or as bump map??
The world isn't unpredictable. It's CHAOTIC.
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???
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???
Whatsoever you do, do it heartily as to the Lord, and not unto men.
That would be the fov you entered in gluPerspective(fov, aspect, zNear, zFar);
The world isn't unpredictable. It's CHAOTIC.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement