Oracle
New member
hey guys,
Im coding opengl and im trying to set up my lighting correctly but i cant sort out these normals and its getting annoying,
I thought i had the normals sorted but on further analysis and testing the normals dont work
thats my display list is there anything glaringly wrong with it?
oracle
Im coding opengl and im trying to set up my lighting correctly but i cant sort out these normals and its getting annoying,
I thought i had the normals sorted but on further analysis and testing the normals dont work
Code:
GLuint adrian(float scale)
{
vertex3 norm;
vertex3 shape[] = {
{0.0f,3.0f,0.0f},// face 1
{1.0f,0.0f,0.0f},
{0.0f,0.0f,1.0f},
{0.0f,3.0f,0.0f},// face 2
{0.0f,0.0f,-2.0f},
{-2.0f,0.0f,0.0f},
{0.0f,0.0f,-2.0f},// face 3
{1.0f,0.0f,0.0f},
{0.0f,-1.0f,0.0f},
{-2.0f,0.0f,0.0f},// face 4
{0.0f,-1.0f,0.0f},
{0.0f,0.0f,1.0f},
{0.0f,0.0f,1.0f},// face 5
{-2.0f,0.0f,0.0f},
{0.0f,3.0f,0.0f},
{1.0f,0.0f,0.0f},// face 6
{0.0f,0.0f,-2.0f},
{0.0f,3.0f,0.0f},
{1.0f,0.0f,0.0f},// face 7
{0.0f,0.0f,1.0f},
{0.0f,-1.0f,.0f},
{0.0f,0.0f,-2.0f},// face 8
{-2.0f,0.0f,0.0f},
{0.0f,-1.0f,0.0f},
};
struct material
{
float ambient[4];
float diffuse[4];
float specular[4];
float shininess[1];
};
material sand = {{0.2f, 0.2f, 0.2f, 1.0f},
{0.92f, 0.72f, 0.21f, 1.0f},
{0.05f, 0.05f, 0.05f, 1.0f},
{1.0}};
GLuint id = glGenLists(1);
glNewList(id, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT, sand.ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, sand.diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, sand.specular);
glMaterialfv(GL_FRONT, GL_SHININESS, sand.shininess);
//face 1
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[1], shape[1], shape[3]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[0].x, shape[3].y, shape[0].z);
glVertex3f(shape[1].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[0].y, shape[1].z);
glEnd();
//face 2
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[3], shape[-2], shape[-2]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[0].x, shape[3].y, shape[0].z);
glVertex3f(shape[0].x, shape[0].y, shape[-2].z);
glVertex3f(shape[-2].x, shape[0].y, shape[0].z);
glEnd();
//face 3
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[-2], shape[1], shape[-1]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[0].x, shape[0].y, shape[-2].z);
glVertex3f(shape[1].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[-1].y, shape[0].z);
glEnd();
//face 4
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[-2], shape[-1], shape[1]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[-2].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[-1].y, shape[0].z);
glVertex3f(shape[0].x, shape[0].y, shape[1].z);
glEnd();
//face 5
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[1], shape[-2], shape[3]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[0].x, shape[0].y, shape[1].z);
glVertex3f(shape[-2].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[3].y, shape[0].z);
glEnd();
//face 6
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[1], shape[3], shape[-2]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[1].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[0].y, shape[-2].z);
glVertex3f(shape[0].x, shape[3].y, shape[0].z);
glEnd();
//face 7
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[1], shape[-1], shape[1]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[1].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[0].y, shape[1].z);
glVertex3f(shape[0].x, shape[-1].y, shape[0].z);
glEnd();
//face 8
glBegin(GL_TRIANGLES);
norm = CalculateCrossProduct(shape[-2], shape[-2], shape[-1]);
glNormal3f(norm.x, norm.y, norm.z);
glVertex3f(shape[0].x, shape[0].y, shape[-2].z);
glVertex3f(shape[-2].x, shape[0].y, shape[0].z);
glVertex3f(shape[0].x, shape[-1].y, shape[0].z);
glEnd();
glEndList();
return id;
}
thats my display list is there anything glaringly wrong with it?
oracle