PDA

View Full Version : Interesting cube mapping problem



robert
01-13-2003, 10:56 AM
Hi all, I am trying out some dynamic cube mapping and I've come to a complete halt.

I don't know how to descirbe it really, and I don't have a webby site to put a screenshot on, but I'll try..

If i look straight on to the sphere that is mapped, I can make out all the faces (xpos,zneg etc) and It looks like it is using the same texture for them all (so It kinda looks like a soccer ball with the indents). But when I move around it the image will change - So at any one time it is reflecting the right image, but none of the other faces are right.

Gah, just gone and confused myself there, I may have to find somewhere to put a screenshot :P.




glViewport(0,0,texDepth,texDepth);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

GLint base = GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;

// Now set up a new perspective
// the fov must be 90
float fieldofview, nearclip, farclip;
getAspectRatio(fieldofview,nearclip,farclip);

gluPerspective(90, 1.0, nearclip, farclip);

glMatrixMode(GL_MODELVIEW);

for (int i = 0; i < 6; ++i)
{
//Clear the depth buffer.
glClear(GL_DEPTH_BUFFER_BIT);

//Reset modelview matrix.
glLoadIdentity();

glTranslatef(pos.x,pos.y,pos.z);

//Rotate
glRotatef(CubeRots[i][0], CubeRots[i][1], CubeRots[i][2], CubeRots[i][3]);


// Now render everything
(world)->Update();

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubemap);


glCopyTexImage2D(base + i, 0, GL_RGB8, 0, 0, texDepth, texDepth,0);
glDisable(GL_TEXTURE_CUBE_MAP_ARB);


}



// Reset THe window
setViewportPersp();


Here are my texgens:




glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);



I know it sounds confusing, but I was just wondering if anyone has had any odd occurances with CM and how they managed to fix it.

[This message has been edited by robert (edited 01-13-2003).]

davepermen
01-13-2003, 12:10 PM
you can always upload on http://davepermen.net just click on free, and upload there, then copy the link(s) in here..

didn't read the post yet, just seen you need webspace

NitroGL
01-13-2003, 12:20 PM
Originally posted by davepermen:
you can always upload on http://davepermen.net just click on free, and upload there, then copy the link(s) in here..

didn't read the post yet, just seen you need webspace

Heh...
You know what? I always figured you as mid 30's, and an American living in California...
http://www.opengl.org/discussion_boards/ubb/smile.gif

jwatte
01-13-2003, 12:26 PM
I always figured you as mid 30's, and an American living in California...


No; I've got a lock on that market :-)

davepermen
01-13-2003, 01:21 PM
hehe.. i'm currently watching futurama, and its 00:20.. and that at the parents home, where i still do live...

not really what you expected, right? http://www.opengl.org/discussion_boards/ubb/biggrin.gif

anyways, lets try to help the original topic http://www.opengl.org/discussion_boards/ubb/biggrin.gif

one day, you know.. one day i get photos..

rgpc
01-13-2003, 02:10 PM
What you've got looks OK.

Are you sure your values in "CubeRots" are correct?

Perhaps the problem is not that it's reflecting the same side of the cube but that your textures are not oriented correctly? ie. Your +Z side is joined to your X sides on the -Z side of those faces... http://www.opengl.org/discussion_boards/ubb/confused.gif

Try swapping your "+Z" and "-Z" to see if it makes a difference.

I know I had a heap of trouble aligning the faces on my cubemaps (only to throw away the idea of dynamic cube maps because render-to-texture is toooooooo slooooooooow!

robert
01-13-2003, 02:13 PM
Hey, thanks for the site http://www.opengl.org/discussion_boards/ubb/smile.gif

I have uploaded the two pictures as: www.itstudents.ch/users/dave/free/files/screenshot4.jpg (http://www.itstudents.ch/users/dave/free/files/screenshot4.jpg)
and www.itstudents.ch/users/dave/free/files/screenshot5.jpg (http://www.itstudents.ch/users/dave/free/files/screenshot5.jpg)

It appears that the cube map is reflecting what the camera sees - fine, I could fix that but I don't understand why it is warping like that...

[This message has been edited by robert (edited 01-13-2003).]

robert
01-13-2003, 02:17 PM
rgpc, I have tried that, but I might have missed something so I'll try again thanks. http://www.opengl.org/discussion_boards/ubb/smile.gif

btw, davepermen nice site! Looks very professional.

rgpc
01-13-2003, 04:44 PM
Looking at your screen shots it is definitely reflecting the same image multiple times...

Just wondering, how do you draw your skybox? Presumably this is done using the "(world)->Update();" call.

Can you show us the code that does this?

It looks like the skybox is not rotated by the rotations in "CubeRots". (So naturally you would get the same image rendered 6 times)

knackered
01-13-2003, 10:54 PM
I really like the idea of people being able to drop stuff onto your site like that, davep. Nice browser thing too. An improvement would be to enable people to attach a comment/link to each item they drop there.

robert
01-14-2003, 11:12 AM
The skybox is just rendered drawing six sides etc.. nothing new there but i can put the code up if you want.





// Negative x-axis
CubeMapRots[0][0] = -90.0f;
CubeMapRots[0][1] = 0.0f;
CubeMapRots[0][2] = 1.0f;
CubeMapRots[0][3] = 0.0f;

// Positive x-axis
CubeMapRots[1][0] = 90.0f;
CubeMapRots[1][1] = 0.0f;
CubeMapRots[1][2] = 1.0f;
CubeMapRots[1][3] = 0.0f;

// Negative y-axis
CubeMapRots[2][0] = -90.0f;
CubeMapRots[2][1] = 1.0f;
CubeMapRots[2][2] = 0.0f;
CubeMapRots[2][3] = 0.0f;

// Positive y-axis
CubeMapRots[3][0] = 90.0f;
CubeMapRots[3][1] = 1.0f;
CubeMapRots[3][2] = 0.0f;
CubeMapRots[3][3] = 0.0f;

// Negative z-axis
CubeMapRots[4][0] = 180.0f;
CubeMapRots[4][1] = 1.0f;
CubeMapRots[4][2] = 0.0f;
CubeMapRots[4][3] = 0.0f;

// Positive z-axis
CubeMapRots[5][0] = 180.0f;
CubeMapRots[5][1] = 0.0f;
CubeMapRots[5][2] = 0.0f;
CubeMapRots[5][3] = 1.0f;



for the positive and negative rotation there I gut of Nutty's website (the cube map demo).

robert
01-14-2003, 09:39 PM
Well fixed it.. I thought at least it might have been something worthwhile all the time I spent trying to figure it out and that people could learn from my mistakes, but alas that was not the case..

I had a popMatrix() with no corresponding popMatrix() that had been left over from something I was doing.

It's times like this when you feel stupid :P.

But an interesting thing is that i can replecate this problem in my code and nutty's code by removing the rendering of objects when the cube map is being made.. I can't quite get my head around why this is so - could someone explain?

knackered
01-14-2003, 11:12 PM
Originally posted by robert:
I had a popMatrix() with no corresponding popMatrix() that had been left over from something I was doing.

Damn, you've done it again!

rgpc
01-14-2003, 11:15 PM
Originally posted by robert:
I had a popMatrix() with no corresponding popMatrix() that had been left over from something I was doing.


Do you mean you had a pushmatrix() without a corresponding popmatrix()? Or a popmatrix() with out a push? http://www.opengl.org/discussion_boards/ubb/smile.gif

Either way the Magical glGetError() (which, according to the red book, should be called at least once per render loop...) would have told that this was happening pretty quickly. (GL_STACK_UNDERFLOW/OVERFLOW)


As for your question regarding nuttys example, what piece of code are you disabling? I disabled the for() loop that draws the objects when updating the cube map and it worked fine...

robert
01-14-2003, 11:47 PM
whoops, yeah replace the second one with a push :P.

Thanks for the tip on glGetError() that would have saved a lot of time.

disable the for loop and the renderskybox(), and that should do it. I'm guessing the resultant behaviour from doing that means the framebuffer is not being updated and that you'd end up taking 6 shots of the same thing?

rgpc
01-15-2003, 12:01 AM
If you disable the skybox and the drawing of the object then you are basically copying a portion of the buffer into each side of the cube map.

Because the code is just calling...




glClear(GL_DEPTH_BUFFER_BIT)


The image copied will be whatever was in the buffer from the last frame displayed. If you look carefully you can just see a portion of the sphere in the cube map.

You only clear the Depth buffer because drawing the skybox will cover the entire screen, so clearing the color buffer would be a waste.