Display lists suck

Started by
3 comments, last by NewDeal 22 years, 9 months ago
Hey, Im having some problems getting my display lists working. The problem lies in the call to glGenList() i think. At least the msg box pops up when i run the function CreateDisplayList()
    
class MS3DModel
{
private:
	
	Mesh *MeshList;
	Material *MaterialList;
	int numVertices, numMeshes, numNormals, numTriangles, numMaterials;
public:
	GLuint listthingy;

	MS3DModel();
	MS3DModel(char *filename);
	~MS3DModel();
	bool LoadFromFile(char *filename);
	void Print(); // for debugging

	void Render();
	void CreateDisplayList();
	void RenderFromDisplayList();
};

void MS3DModel::CreateDisplayList()
{
	listthingy = glGenLists(1);

	if (listthingy == 0) 
	{
		MessageBox(NULL,"FUCK!!","ERROR",MB_OK|MB_ICONEXCLAMATION);
	}

	glNewList(listthingy, GL_COMPILE);
	glBegin(GL_TRIANGLE_STRIP);
	for (int m=0; m<numMeshes; m++)
	{
		
		for (int t=0; t<numTriangles; t++)
		{
			glTexCoord2f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[0]].u, 
MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[0]].v);
			glVertex3f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[0]].location[0] , 
					   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[0]].location[1],  
					   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[0]].location[2]);
			
			glTexCoord2f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[1]].u, 
MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[1]].v);
			glVertex3f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[1]].location[0] , 
					   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[1]].location[1],  
					   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[1]].location[2]);
			
			glTexCoord2f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[2]].u, 
MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[2]].v);
			glVertex3f(MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[2]].location[0] , 
			     	   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[2]].location[1],  
					   MeshList[m].VerticesList[MeshList[m].TrianglesList[t].VertexIndices[2]].location[2]);

		}
		
	}
	glEnd();
	glEndList();
}
    
I got another function called Render() which has pretty much the same code as CreateDisplayList() except the list commands ofcourse, and that function works like a charm. BTW glGenLists() return 0 if an error occurs. Can figure out what goes wrong though. Hope you can help me out. Thanks in advance Edited by - newdeal on July 12, 2001 7:17:14 PM
Advertisement
Well, just found this in some developers journal. Too bad i have no clue what the guy''s saying . Maybe you do.

quote:
"Well, that certainly sucked. Just spent the last two days tracking down why glGenLists() kept returning 0 and all display lists weren''t working. I came to the conclusion that it had to do with GL context init - the ortho views share the same display lists as the perspective view, but they are created before the context is initialized. Theoretically, it was Qt''s fault. I''ve got to organize the GL stuff, though."
The first place to look is glGetError(). If the return value of glGetError() == GL_NO_ERROR, then you''re really going to have fun . There are only a few errors defined in OpenGL, and some of them, such as GL_STACK_OVERFLOW, have no effect on the program other than to set the error flag. Check out the Blue Book for a complete list of the error defines (or gl.h).
There are 2 things that I would make sure of. First make sure that you are generating your lists AFTER you initialize OpenGL. And make sure that you are not calling glBegin before generating the display list. Either of those situations would cause glGenLists to fail and return GL_INVALID_OPERATION from glGetError.

Seeya
Krippy
Problem solved! I was creating the lists before OpenGL was properly initialized.

Thanks guys

This topic is closed to new replies.

Advertisement