Hi,
I´ve got a problem when I draw my objects. I can see the outlines of the object, or the dots of the vertex, but the polygons are not
always filled. I´ve tried with glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) and I´ve tried with glFrontFace(GL_CCW) or GL_CW but only some polygons are shown. It almost feels like I´ve done something stupied with the light. I don´t use normals, so the light shouldn´t bother, should it??
What might be wrong???
Thanks!!
/grodslukaren
my code is below.
// InitGL - initiate the ambient of the OpenGL Canvas
void C3DPaintCanvas::InitGL()
{
SetCurrent();
glClearColor(0.0f, 0.0f, 0.0f, 0.0);
GLfloat light0_pos[4] = { 0.0, 0.0, -100.0, 0.0 }; // light position
float a[] = {0.4F, 0.4F, 0.4F, 1.0F}; // ambient light
float d[] = {1.0F, 1.0F, 1.0F, 1.0F}; // diffuse light
float e[] = {1.0F, 1.0F, 1.0F, 1.0F}; // specular light
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, a);
glLightfv(GL_LIGHT0, GL_DIFFUSE, d);
glLightfv(GL_LIGHT0, GL_SPECULAR, e);
float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0}; // 1,1,1,1
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glClearDepth(1.0f);
glDepthFunc(GL_LESS);
glDepthRange(0.01, 1000.0);
glDisable(GL_BLEND);
glDepthMask (GL_TRUE);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
// cull polygons based on their winding in window coordinates
glEnable(GL_CULL_FACE);
// selects flat or smooth shading
glShadeModel(GL_SMOOTH);
// enable colors
glEnable(GL_COLOR_MATERIAL);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
// speedups
// dither color components or indexes before they are written to the color buffer
glEnable(GL_DITHER);
// specifies implementation-specific hints
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
// Perspective
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// set the coordinate system and the "camera"
glOrtho(-300,300,-300,300,-300,300);
glTranslatef( 0.0f, 0.0f, -200.f ); // change the distance to the object (last one)
}
void C3DPaintCanvas::Render()
{
int i,vert;
vert=0;
wxPaintDC dc(this);
// sets this canvas as the current recipient of OpenGL calls
SetCurrent();
// init OpenGL once, but after SetCurrent
if (!m_init)
{
InitGL();
m_init = true;
// to move the object and not the camera
glMatrixMode(GL_MODELVIEW);
}
// clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// rotate the head
glRotatef( m_dXAngle, 1.0f, 0.0f, 0.0f );
glRotatef( m_dYAngle, 0.0f, 1.0f, 0.0f );
// draw the face from the coordinates in m_pFaceMesh
glFrontFace(GL_CW);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 1.0, 1.0); // set the color for the face
for (i=0; i<m_pFaceMesh->vertNumber; i++)
{
glVertex3f(m_pFaceMesh->vertice[i].x,
m_pFaceMesh->vertice[i].y, m_pFaceMesh->vertice[i].z);
}
glEnd();
// draw the scalp from the coordinates in m_pScalpMesh
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
for (i=0; i<m_pScalpMesh->vertNumber; i++)
{
// for each vertice, set the color stored in m_pMesh->verProj[i]
//glColor3f(m_pMesh->verProj[i].r, m_pMesh->verProj[i].g, m_pMesh->verProj[i].b);
glVertex3f(m_pScalpMesh->vertice[i].x,
m_pScalpMesh->vertice[i].y, m_pScalpMesh->vertice[i].z);
}
glEnd();
glFlush();
SwapBuffers();
}