glTexGeni generating wrong textcoord for cubeenv

Hi

I’m using glTexGeni to generate the texture coordinates for an object that is supposed to reflect an environment map.

It seems like the normals (viewXnormal) point in the opposite direction. So, when a surface is supposed to point downwards, it reflects upwards.

Does anyone know whether this is a bug in jogl?

I know I have my own normals correct, so that won’t be what causes the problem.

I use this code to generate the coords:

myGL.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
myGL.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
myGL.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
myGL.glEnable(GL.GL_TEXTURE_GEN_S);
myGL.glEnable(GL.GL_TEXTURE_GEN_T);
myGL.glEnable(GL.GL_TEXTURE_GEN_R);
myGL.glEnable(GL.GL_NORMALIZE);

I find it hard to describe the problem.
I render a cube, and try to do some reflections on it.
The end result though is that the reflections end up like refractions, which is cool in its own way, but not what I want to achieve. Now… I’m pretty sure my code is ok, but one can never be to shure.

Have anyone else tried the GL_TEXTURE_CUBE_MAP_ARB extension successfully with jogl?

Hi,

We successfully implemented TextureCubeMaps in Xith3D using this extension.

The most important problem that you may encounter with this is influence of current transform to the texture coord generation process. I suggest you to experiment first with identity transforms.

Yuri

I’ve created a simple code testing the cubemapping, but the effect is still that of a refracted mapping, and not that of a reflection. I’ll post the code here:

Cubemap is enabled, and automatic texturegeneration is set with

    myGL.glEnable(GL.GL_TEXTURE_CUBE_MAP);
    myGL.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, textures[1]); 

    /**
     * Generate coordinates
     */
    myGL.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
    myGL.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
    myGL.glTexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, GL.GL_REFLECTION_MAP_ARB);
    myGL.glEnable(GL.GL_TEXTURE_GEN_S);
    myGL.glEnable(GL.GL_TEXTURE_GEN_T);
    myGL.glEnable(GL.GL_TEXTURE_GEN_R);
    myGL.glEnable(GL.GL_NORMALIZE);

A square is drawn with:

    int width = canvas.getWidth();
    int height = canvas.getHeight();
    myGL.glMatrixMode(GL.GL_PROJECTION);
    myGL.glLoadIdentity();
    float aspect = height / (float) width;
    myGL.glFrustum(-1, 1, -1 * aspect, 1 * aspect, 2, 50);
    myGL.glTranslatef(0, 0, -4);


    myGL.glMatrixMode(GL.GL_MODELVIEW);
    myGL.glLoadIdentity();
    myGL.glRotatef(-45, 1, 0, 0);

    myGL.glBegin(GL.GL_QUADS);
    myGL.glNormal3f(0.0f,0.0f,1.0f);
    myGL.glVertex3f(-1.0f,-1.0f,1.0f);
    myGL.glVertex3f(1.0f,-1.0f,1.0f);
    myGL.glVertex3f(1.0f,1.0f,1.0f);
    myGL.glVertex3f(-1.0f,1.0f,1.0f);
    myGL.glEnd();

This square is rotated, so that it should have reflected the top of the cubemap, but instead it displays the bottom (-y).

I realize that my texture might be wrong. Does anyone have a link to a page where there is a good explanation of how to create a cubic environment map?

Hehe… I just started a discussion with myself it seems.

Anyways… I realized that I have more problems than I earlier thoght. Even though I change my viewpoint, the same part of the cubemap is projected on the square.

This is supposed to change when i move the viewpoint ( do transformation on the PROJECTION matrix? Or am I totally lost here?

Hi,

I know this will not be of much help, but at least to ensure that texture cube mapping works with JOGL, you can try TextureCubeMap demo from thread http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1071038323 in Xith3D forum.

[quote]This is supposed to change when i move the viewpoint ( do transformation on the PROJECTION matrix?
[/quote]
As of my experience, if you combine viewpoint (camera) transform with projection transform, it will break TextureCubeMap texture coordinate generation. This is exactly what I meant with current transform problems.

Yuri

Thanks for your help Yuri, but I’m still kindof stuck.
I thought that glTexGenX would generate the projected textures based on the angle between the viewpoint and the normal of the vertex.

And about the projection and modelview transformations. It still doesn’t work, even though I drop the modelview transformation.
But seriously, this shouldn’t cause problems, should it?

I’ve learned one thing though… My GL knowledge isn’t as good as I thought it was.

I will end my ranting with a final note:

I’ve used GL.GL_REFLECTION_MAP_ARB. I do it the same way, as done in other examples.
But:

Texturemapping is view independent.
cubic reflection mapping should be view dependent.

The generated texture coordinates are projected along the vertex normals, but map to the wrong side of the cube. This happens wether or not I am doing any transformations on the modelview matrix or on the projection matrix.

I can create something that LOOK like reflections, but if you watch closely, they aren’t. Their just mappings along the normals. Reflectons are mappings that are based on the view normal reflected by the plane defined by the vertex normal.

The faulty texturegeneration happens wether I use quadrics or draw my own geometry.

Pardon me for being so frank, but I consider this as a bug with jogl, or my gpu driver, as I’ve been playing around with this for several day’s now, reading everything I can get over, dooing it exactly to the specs, but still the texturemapping is incorrect.

Have anyone else experienced these problems?

Jogl v1.0
Geforce Ti 4400
Driver version 5.3.0.3