hello
I have a problem with bump mapping, when displaying the model MD2. The effect works fine if the model is illuminated from the front. If the light is behind it is not illuminated back side of the model. The code is simple to me. I think that the problem lies in determining the normal triangle. I wrote this function using the materials on the forum but got no satisfactory result.
[source lang="cpp"]glActiveTextureARB (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_CUBE_MAP, NORMALIZATION_CUBE_MAP);
glEnable (GL_TEXTURE_CUBE_MAP);
glTexEnvi (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_REPLACE);
glTexEnvi (GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_TEXTURE);
glActiveTextureARB (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_2D, NORMAL_TEXTURE);
glEnable (GL_TEXTURE_2D);
glTexEnvi (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_DOT3_RGB);
glTexEnvi (GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS);
glTexEnvi (GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE);
glActiveTextureARB (GL_TEXTURE2);
glBindTexture (GL_TEXTURE_2D, BASE_TEXTURE);
glEnable (GL_TEXTURE_2D);
glTexEnvi (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glBegin(GL_TRIANGLES);
for(i = 0; i < numTriangles; i++) {
MD2Normal (List[tindex.Index[0]].point,
List[tindex.Index[1]].point,
List[tindex.Index[2]].point);
GLfloat Light_vector[3];
for (GLint u = 0; u < 3; u++) {
Light_vector[0] = light_pos[0] - List[tindex.Index].point[0];
Light_vector[1] = light_pos[1] - List[tindex.Index].point[1];
Light_vector[2] = light_pos[2] - List[tindex.Index].point[2];
glMultiTexCoord3fv (GL_TEXTURE0, Light_vector);
glMultiTexCoord2fARB (GL_TEXTURE1, bst[triIndex.stIndex].s, bst[triIndex.stIndex].t);
glMultiTexCoord2fARB (GL_TEXTURE2, st[triIndex.stIndex].s, st[triIndex.stIndex].t);
glVertex3fv (List[tindex.Index].point);
}
}[/source]
Calculating the normal vector for each triangle
[source lang="cpp"]GLvoid MD2Normal (GLfloat *p1, GLfloat *p2, GLfloat *p3) {
GLfloat a[3], b[3], result[3];
GLfloat length;
GLfloat normal[3];
a[0] = p1[0] - p2[0];
a[1] = p1[1] - p2[1];
a[2] = p1[2] - p2[2];
b[0] = p1[0] - p3[0];
b[1] = p1[1] - p3[1];
b[2] = p1[2] - p3[2];
result[0] = a[1] * b[2] - b[1] * a[2];
result[1] = b[0] * a[2] - a[0] * b[2];
result[2] = a[0] * b[1] - b[0] * a[1];
length = (GLfloat)sqrt(result[0]*result[0] + result[1]*result[1] + result[2]*result[2]);
normal[0] = result[0]/length;
normal[1] = result[1]/length;
normal[2] = result[2]/length;
glNormal3f(normal[0], normal[1], normal[2]);
}[/source]
So as I wrote the code itself is simple - trivial. I wonder just where is the problem here?
Thank you for your help.
[OpenGL] MD2 bumpmapping weird results - newbie question
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement