Furrage
03-18-2002, 06:48 AM
Why would the following code only draw some of the objects some of the time? I may run the program and everything draws. Then I may run the program again and everything draws the first frame, then only the first object get's drawn after that.
All objects are in a curcular linked list. FocalPoint points to the first object in the list. Relvec give the vector relative to FocalPoint's Location, CentreX and CentreY gives the projection's centre. Size = 3.5. I've counted how many times each object is drawn using DrawCount and it matches how many frames are drawn.
glLoadIdentity(); // Clear matrix.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Clear colour and double buffer.
glTranslated(CentreX, CentreY, -1);
// Translate to screen's centre.
ogsObject *tObject = Game->Objects->Next;
// Create pointer to object.
glColor3f(0.8f, 0.8f, 0.4f);// Set object colour.
while (tObject != Game->Objects) {
// For each object in game.
if (tObject->IsSet(ogsVISIBLEFLAG)) {
// If object is visible.
glPushMatrix(); // Save current matrix.
tVec = FocalPoint->RelVec(tObject->Loc);
// Get position of object relative to focal point.
glTranslated(tVec.x, tVec.y, 0);
// Translate to object's relative position.
glRotated(tObject->Dir, 0, 0, -1);
// Rotate to direction object faces.
glBegin(GL_TRIANGLES);
// Draw triangle.
// (TODO) remove diagnostic output.
++tObject->DrawCount;
glVertex2d(0, tObject->Size);
glVertex2d(-tObject->Size * 0.7, -tObject->Size * 0.7);
glVertex2d(tObject->Size * 0.7, -tObject->Size * 0.7);
glEnd();
glPopMatrix(); // Restore current matrix.
}
tObject = tObject->Next;// Move to next object.
}
All objects are in a curcular linked list. FocalPoint points to the first object in the list. Relvec give the vector relative to FocalPoint's Location, CentreX and CentreY gives the projection's centre. Size = 3.5. I've counted how many times each object is drawn using DrawCount and it matches how many frames are drawn.
glLoadIdentity(); // Clear matrix.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Clear colour and double buffer.
glTranslated(CentreX, CentreY, -1);
// Translate to screen's centre.
ogsObject *tObject = Game->Objects->Next;
// Create pointer to object.
glColor3f(0.8f, 0.8f, 0.4f);// Set object colour.
while (tObject != Game->Objects) {
// For each object in game.
if (tObject->IsSet(ogsVISIBLEFLAG)) {
// If object is visible.
glPushMatrix(); // Save current matrix.
tVec = FocalPoint->RelVec(tObject->Loc);
// Get position of object relative to focal point.
glTranslated(tVec.x, tVec.y, 0);
// Translate to object's relative position.
glRotated(tObject->Dir, 0, 0, -1);
// Rotate to direction object faces.
glBegin(GL_TRIANGLES);
// Draw triangle.
// (TODO) remove diagnostic output.
++tObject->DrawCount;
glVertex2d(0, tObject->Size);
glVertex2d(-tObject->Size * 0.7, -tObject->Size * 0.7);
glVertex2d(tObject->Size * 0.7, -tObject->Size * 0.7);
glEnd();
glPopMatrix(); // Restore current matrix.
}
tObject = tObject->Next;// Move to next object.
}