Sign in to follow this  
manonoc

error GL_INVALID_OPERATION in glEnd()

Recommended Posts

Hi, I have implemented two drawing functions, one with the Begin/End and an other with DrawElements: the images are there: http://escetlp.free.fr/BeginEnd.jpg http://escetlp.free.fr/DrawElements.jpg
/*
///////////////////////////////////////////////////////////////////////////////////////////
void cAPI_3D_SDL::DrawAStaticBody(cStaticBody *pDecor)
{
	LOGUER_FONCTION_DEBUT("cAPI_3D_SDL::DrawAStaticBody");

	for (int i=0; i<pDecor->GetMesheCount(); i++)
	{
		// on utilise beaucoup le meshe MesheCourant
		cMeshe	*MesheCourant = pDecor->GetMeshe(i);
		cVector3	V;

		LOGUER_INSTANCE(*MesheCourant)

		// spécification du matériaux pour les triangles du meshe
		glBegin( GL_TRIANGLES );TEST_ERROR_GL
		cMaterial	*mat = pDecor->GetMateriaux(MesheCourant->GetMaterialNb());
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat->Ambient);TEST_ERROR_GL
		glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->Diffuse);TEST_ERROR_GL
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat->Specular);TEST_ERROR_GL
		glMaterialf(GL_FRONT, GL_SHININESS, mat->Shininess);TEST_ERROR_GL



//IL FAUT D'ABORD LISTER LES FACES, ET POUR chaque face, envoyer les 3 vertex;
		// on boucle sur les faces, pour envoyer les meshes
		for (int i=0; i<MesheCourant->GetFacesCount(); i++)
		{
			// pour une face, on a 3 vertex
			V = MesheCourant->GetVertexFromFace(3*i)->world_pos;
			glVertex3fv((float*)&V);TEST_ERROR_GL
			V = MesheCourant->GetVertexFromFace(3*i)->world_nor;
			glNormal3fv((float*)&V);TEST_ERROR_GL
			V = MesheCourant->GetVertexFromFace(3*i+1)->world_pos;
			glVertex3fv((float*)&V);TEST_ERROR_GL
			V = MesheCourant->GetVertexFromFace(3*i+1)->world_nor;
			glNormal3fv((float*)&V);TEST_ERROR_GL
			V = MesheCourant->GetVertexFromFace(3*i+2)->world_pos;
			glVertex3fv((float*)&V);TEST_ERROR_GL
			V = MesheCourant->GetVertexFromFace(3*i+2)->world_nor;
			glNormal3fv((float*)&V);TEST_ERROR_GL
		}
		glEnd();TEST_ERROR_GL


		// draw the normals en blue
		glDisable(GL_LIGHTING);
		glBegin(GL_LINES);TEST_ERROR_GL
		glColor3f(0.f, 0.f, 1.f);
		for (int i=0; i<MesheCourant->GetVerticesCount(); i++)
		{
			V = MesheCourant->GetVertex(i)->world_pos;
			glVertex3fv((float*)&(V));TEST_ERROR_GL
			V += MesheCourant->GetVertex(i)->world_nor;
			glVertex3fv((float*)&(V));TEST_ERROR_GL
		}
		glEnd();TEST_ERROR_GL
		glEnable(GL_LIGHTING);
	}

	LOGUER_FONCTION_FIN("cAPI_3D_SDL::DrawAStaticBody");
}
*/


///////////////////////////////////////////////////////////////////////////////////////////
void cAPI_3D_SDL::DrawAStaticBody(cStaticBody *pDecor)
{
	LOGUER_FONCTION_DEBUT("cAPI_3D_SDL::DrawAStaticBody");


	for (int i=0; i<pDecor->GetMesheCount(); i++)
	{
		// on utilise beaucoup le meshe MesheCourant
		cMeshe	*MesheCourant = pDecor->GetMeshe(i);

	// client states
	glEnableClientState(GL_VERTEX_ARRAY);TEST_ERROR_GL
	glEnableClientState(GL_NORMAL_ARRAY);TEST_ERROR_GL
		
		glPushMatrix();TEST_ERROR_GL
		glLoadMatrixf(cMatrix44(pDecor->Get_R(), pDecor->Get_x()).GetPointer());TEST_ERROR_GL

		cMaterial	*mat = pDecor->GetMateriaux(MesheCourant->GetMaterialNb());
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat->Ambient);TEST_ERROR_GL
		glMaterialfv(GL_FRONT, GL_DIFFUSE, mat->Diffuse);TEST_ERROR_GL
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat->Specular);TEST_ERROR_GL
		glMaterialf(GL_FRONT, GL_SHININESS, mat->Shininess);TEST_ERROR_GL

		glVertexPointer(3, GL_FLOAT, sizeof(cVertex), (GLvoid *)((cVector3*)MesheCourant->GetVerticesArray()));TEST_ERROR_GL
		glNormalPointer(   GL_FLOAT, sizeof(cVertex), (GLvoid *)((cVector3*)MesheCourant->GetVerticesArray()+1*sizeof(cVector3)));TEST_ERROR_GL
		
		glDrawElements(GL_TRIANGLES, MesheCourant->GetFacesCount(), GL_UNSIGNED_INT, (void *)(MesheCourant->GetFacesArray()));TEST_ERROR_GL
		
		glPopMatrix();TEST_ERROR_GL

	// client states
	glDisableClientState(GL_VERTEX_ARRAY);TEST_ERROR_GL
	glDisableClientState(GL_NORMAL_ARRAY);TEST_ERROR_GL
	}


	LOGUER_FONCTION_FIN("cAPI_3D_SDL::DrawAStaticBody");
}
The first version draw correctly all the triangles, but the second draw not all the triangles (do not care of the blue normals). And there is an error on the first version (glGetError = 1282) but no error in the second version: there the class cVertex:
class cVertex
{
public:

	cVector3	body_pos;
	cVector3	body_nor;
	cVector3	world_pos;
	cVector3	world_nor;
};
I doesn't understand why there is this error and why all the triangle aren't drawn with DrawElements. Is someone could explain to me. thanks.

Share this post


Link to post
Share on other sites

  • The specification states that any command that is not valid is completely ignored and the proper error bit is set. Calling glGetError in a Begin/End-pair is not valid, and so the command is ignored the GL_INVALID_OPERATION error bit is set. Directly after the Begin/End-pair, the error is returned, because that's the first valid call to glGetError after the error occured.

  • You're specifying normals after the vertex is issued. When a vertex is spcified, the current normal, color, texture coordinate and whatever else is assigned to it. Since you call glNormal AFTER glVertex, the normal will be assinged to the next vertex instead.

  • The count parameter to glDrawElements is not the face count, but the number of indices in the index array.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this