PDA

View Full Version : material problem when using displaylist



Dolth
02-18-2010, 05:40 PM
I can switch between 2 screens, one (screen A) uses yellow diffuse material, the other (screen B) red.

screen A shows good B aswell, back to A and the letters are grey.
Screen B keeps showing what i intended it to show.

The problems seems to be with the 'glCallList(1)' line but i can't figure out what's wrong.

Thanks in advance for taking a look at it:

screen A:


void gamescreen()
{

glPushMatrix();
glTranslatef(0.0,0.0,zoom);
glRotatef(rotate[0],0.0,1.0,0.0); glRotatef(rotate[1],cos(rotate[0]*PI/180.0),0.0,sin(rotate[0]*PI/180.0));
glTranslatef(translate[0],translate[1],translate[2]);
GLfloat diffuse[] = { 1.0f,0.0,0.0 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
for (int i=0;i<aantalplaneten;i++)
{
glPushMatrix();
glLoadName(i+1);
glTranslatef(coordinaten[i][0],coordinaten[i][1],coordinaten[i][2]);
glCallList(1); //comment this out and no problem :'(
glPopMatrix();
}
glPopMatrix();
}


screen B


void titlescreen()
{
GLfloat diffuse[] = { 1.0,1.0,0.0 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glLoadName(SCR_NEWGAME);
text::maak("new game",0.8f,-4.0,1.5f,-10.0);
//text::maak just defines some GL_TRIANGLES to make characters
glLoadName(SCR_SETTINGS);
text::maak("settings",0.8f,-4.0,0.0f,-10.0);
glLoadName(SCR_EXIT);
text::maak("exit",0.8f,-4.0,-1.5,-10.0);
}


and finaly the creation of the list:


void displistinit()
{
GLfloat vdata[12][3]=
{
{-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
{0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
{Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
};
GLint tindices[20][3]=
{
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
{8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
{6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
};

glNewList(1, GL_COMPILE);
for (int i = 0; i < 20; i++)
{
subdivide(&amp;vdata[tindices[i][0]][0], &amp;vdata[tindices[i][1]][0], &amp;vdata[tindices[i][2]][0],3);
}
glEndList();
}

void normalize(float v[3])
{
GLfloat d = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
v[0] /= d; v[1] /= d; v[2] /= d;
}

void drawtriangle(float *v1, float *v2, float *v3)
{
glBegin(GL_TRIANGLES);
glNormal3fv(v1); glVertex3fv(v1);
glNormal3fv(v2); glVertex3fv(v2);
glNormal3fv(v3); glVertex3fv(v3);
glEnd();
}

void subdivide(float *v1, float *v2, float *v3, long depth)
{
GLfloat v12[3], v23[3], v31[3];
GLint i;
if (depth == 0)
{
drawtriangle(v1, v2, v3);
return;
}
for (i = 0; i < 3; i++)
{
v12[i] = v1[i]+v2[i];
v23[i] = v2[i]+v3[i];
v31[i] = v3[i]+v1[i];
}
normalize(v12);
normalize(v23);
normalize(v31);
subdivide(v1, v12, v31, depth-1);
subdivide(v2, v23, v12, depth-1);
subdivide(v3, v31, v23, depth-1);
subdivide(v12, v23, v31, depth-1);
}

Dolth
02-19-2010, 02:24 AM
Sorry for the waste of time.

After a nice nights rest it suddenly did hit me: no normals defined in the naughty screen. So after swapping the screens a 'random' normal was used for one screen, defined my own normals and that solved it.