Dot3 Bump Mapping (little) problem

Hi again :slight_smile:

I’ve made a little lwjgl application which use Dot3 bump mapping (3 extensions needed : EXTTextureEnvCombine, EXTTextureEnvDot3, ARBMultitexture) but I’ve got a little problem.

The bump mappig process works, but textures colors are very strange…

Hum I think the best way is to show you some screenshots :

http://hourdel.chez.tiscali.fr/private/snap006.jpg

http://hourdel.chez.tiscali.fr/private/snap007.jpg

Ok so as you can see, the bump mapping works except on the strange color problem…

Here is my rendering code :


private final void render()
{
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();

            glTranslatef(0.0f,0.0f,-5.0f);
            glRotatef(rotY, 0.0f, 1.0f, 0.0f);

            glActiveTextureARB(GL_TEXTURE0_ARB);
            glBindTexture(GL_TEXTURE_2D, texture2.id);
            glEnable(GL_TEXTURE_2D);

            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
            glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);
            glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRIMARY_COLOR_EXT);
            glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
            glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
            glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
            
            glActiveTextureARB(GL_TEXTURE1_ARB);
            glBindTexture(GL_TEXTURE_2D, texture.id);
            glEnable(GL_TEXTURE_2D);

            glBegin(GL_QUADS);
                glNormal3f( 0.0f, 0.0f, 1.0f);
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  0.0f);
                glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  0.0f);
            glEnd();

            glActiveTextureARB(GL_TEXTURE1_ARB);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glDisable(GL_TEXTURE_2D);

            glActiveTextureARB(GL_TEXTURE0_ARB);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glDisable(GL_TEXTURE_2D);
      }

Edit: “texture” is the base texture and “texture2” is the bump map.

Can someone help me ? If you want more coding part, simply ask but I think the bug is in this part…
Thanks in advance :slight_smile:

Chman

Ok I’ve fixed the problem… It was just a stupid error in texture coordinates…

Chman

(and once again, an unuseful post :-X)

I’ve been playing around with multitexturing recently and I thought I’d try out the example above, doesn’t seem to work right for me. Is there anything else that has to be added to the above code to get bump mapping working as the code above just adds highlights to the texture, rather than a light reactive bump map?

Also, I’ve been browsing the net looking for none shader bump mapping techniques and a common one I’ve found is this : http://www.paulsprojects.net/tutorials/simplebump/simplebump.html, (nehe#20 links to this tut) Its uses a normalized cube map to calculate the, err, magic:)

However I’m having trouble converting this bit of C code to java.


      GL11.glGenTextures(textureId);
      glBindTexture(GL_TEXTURE_CUBE_MAP, texid);

      unsigned char* data = new unsigned char[size*size*3];

      float offset = 0.5f;
      float halfSize = size * 0.5f;
      float[] temp = {0f, 0f, 0f};
      int bytePtr = 0;

      for(int j=0; j<size; j++)
      {
            for(int i=0; i<size; i++)
            {
                  temp[0] = halfSize;
                  temp[1] = (j+offset-halfSize);
                  temp[2] = -(i+offset-halfSize);
                  scale_to_01(temp);//i think this method multiplies the vector by 0.5 than adds 0.5 to it.

                  data[bytePtr] = (unsigned char)(temp[0] * 255.0f);
                  data[bytePtr+1] = (unsigned char)(temp[1] * 255.0f);
                  data[bytePtr+2] = (unsigned char)(temp[2] * 255.0f);

                  bytePtr+=3;
            }
      }
      glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                  0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

The part I’m having trouble with is the unsigned char parts, I guess this needs to be a byteBuffer but (being rubbish with byteBuffers) I have no idea how to get this bit of code working with them. Can someone point me in the right direction?

Also are there other more straight forward ways for creating the bump mapping effect, preferably with openGL doing all the work :slight_smile:

Cheers all

[edit], I think I’ve sorted it out, wont be able to test it tomorrow though.

Has anyone converted this tutorial to LWJGL yet ?
http://nehe.gamedev.net/data/articles/article.asp?article=20

If not I’ve got it working so if anyone wants just pop me a message, only got it working on a quad though, cant get it working an a mesh.

Might be of use to someone, never know.

An old bump (no pun intended!), but just wondering if anyone here has any working Dot3 bump mapping JOGL code. Im really struggling trying to convert the C from this article to JOGL.

Cheers,