0
101 Aug 09, 2009 at 02:00

I’ve been debugging through a problem I’ve had the past couple days with lighting my terrain engine. Below are the before/after pics of the lighting problem and the same picture of it after the problem was fixed (notice the odd striping effect on the first pic).

This is the code now:

normalBuffer.put(i, normalMap.get(yPos, xPos).getX());
normalBuffer.put((i+1), normalMap.get(yPos, xPos).getY());
normalBuffer.put((i+2), normalMap.get(yPos, xPos).getZ());

vertexBuffer.put(i, xPos);
i++;
vertexBuffer.put(i, heightVal);
i++;
vertexBuffer.put(i, yPos);
i++;


These are vertex and normal arrays (I’m not using VBOs). The problem was I had the normalBuffer code above being placed after the vertexBuffer code. Now I realize in immediate mode that all the attributes of the vertex should be called before the glVertex draw code, but this is just populating the arrays for rendering later, so it is confusing me that this was the issue. Just wanting to know if anyone has some input on this.

#### 2 Replies

0
167 Aug 09, 2009 at 04:23

Well, the vertexbuffer section has a bunch of i++’s in it, so having the normalbuffer code underneath that would presumably store the normals to the wrong spot in the buffer.

0
101 Aug 09, 2009 at 06:26

vertexBuffer.put(i, xPos);
i++;
vertexBuffer.put(i, heightVal);
i++;
vertexBuffer.put(i, yPos);
i++;

normalBuffer.put(i-2, normalMap.get(yPos, xPos).getX());
normalBuffer.put(i-1, normalMap.get(yPos, xPos).getY());
normalBuffer.put(i, normalMap.get(yPos, xPos).getZ());


So I just realized my mistake there. Sighhh… always the minor issues.