Hello. I’m attempting to render a very simple normal map scene. I’m making a 2d program for now so every object drawn will always be on a quad facing in the same direction, as I didn’t want to get into too complex of 3d to start.
I would however like to use normal mapping and lighting for some shading effect and am having difficulty understanding how to set up the normals for this.
Here is the relevant code which works for lighting, but the moving the light around just increases intensity and doesn’t change the direction so I’m guessing I have my normals wrong?
GLfloat vertices[] = {1,1,1, -1,1,1, -1,-1,1, 1,-1,1};
GLubyte indices[] = {0,1,2,3};
GLfloat textureCoords [] = {1.0f,0.0f, 0.0f,0.0f, 0.0f,1.0f, 1.0f,1.0f};
GLfloat normals[] = {0,0,1, 0,0,1, 0,0,1, 0,0,1};
//....
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 0,textureCoords);
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, 0,textureCoords);
glNormalPointer(GL_FLOAT, 0, normals);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, indices);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
The result of the normal map and my texture shows up, so I think I have that correct, just the light direction is always the same. Could someone let me know the correct normals to use on a simple quad that will always be facing the user? Thanks.