Problem changing from line to filled polygon

hi there,

I got problem changing from line to smooth filling using glPolygonMode(…)…
here is my code

if(choice == 0) {
        objList = glGenLists(1);
		glNewList(objList, GL_COMPILE);
		defGeo.drawSphere(radius, surfaces, surfaces);
		glEndList();
	}else if(choice == 1) {
        objList = glGenLists(2);
		glNewList(objList, GL_COMPILE);
		defGeo.drawTorus(radius, surfaces, surfaces, 20, 20);
		glEndList();
	}else if(choice == 3) {
        objList = glGenLists(3);
		glNewList(objList, GL_COMPILE);
		defGeo.drawWeirdParabolic(radius, surfaces, surfaces);
		glEndList();
	}

	glClearColor(0, 0, 0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	
	glOrtho(
		-tw/2.0, tw/2.0, 
		-th/2.0, th/2.0, 
		-300.0, 300.0
	);

	/*glFrustum(
		-tw/2.0, tw/2.0, 
		-th/2.0, th/2.0, 
		-300.0, 300.0
	);*/
	
	glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
	if(lighting0) {
		glEnable(GL_LIGHT0);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_intensity);
		//glLightfv(GL_LIGHT0, GL_AMBIENT, light1_amb);
		glLightfv(GL_LIGHT0, GL_POSITION, light0_dir);
	}else {
		glDisable(GL_LIGHT0);
	}

	if(lightingMove) {
		glEnable(GL_LIGHT1);
		glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_intensity);
		//glLightfv(GL_LIGHT1, GL_AMBIENT, light1_amb);
		glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 2.0);
		glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.0);
		glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.5);
		glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);
		glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);
	}else {
		glDisable(GL_LIGHT1);
	}

	glTranslatef( 0.0, 0.0, -2.6f );
	glTranslatef( objTranslation[0], objTranslation[1], -objTranslation[2] ); 
	glMultMatrixf( objRotation );

	glPushMatrix();
	//glTranslatef( -.5, 0.0, 0.0 );

	glColor3f(1.0, 1.0, 1.0);

	if(wireframe == 1) {
		//DisplayFunc();
		//printf("Wireframe");
        glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
		glCallList(objList);

		glPopMatrix();
		glutSwapBuffers();

		glutPostRedisplay();
	} else if(wireframe == 0) {
		//DisplayFunc();
		//glPolygonMode( GL_FRONT_AND_BACK, GL_SMOOTH);
		//printf("Not Wireframe");
		glShadeModel(GL_SMOOTH);
		glCallList(objList);

		glPopMatrix();
		glutSwapBuffers();

		glutPostRedisplay();
	}
	
	}

wireframe var is conroller by the glui checkbox so whenever i checked and uncheck it it should change from wireframe mode and filling mode but it didnt work… please help me thanks you in advance

Pick up the OpenGL reference manual if you haven’t already, its very usefull for situations like this. You need to be looking at glPolygonMode. You have it in there now after you’ve checked that WireFrame == 0 but its commented out and the second parameter is not a valid value to pass. You want to set it to GL_FILL instead of GL_SMOOTH.

if(wireframe == 1) {		//DisplayFunc();		//printf("Wireframe");        glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);		glCallList(objList);		glPopMatrix();		glutSwapBuffers();		glutPostRedisplay();	} else if(wireframe == 0) {		//DisplayFunc();		//glPolygonMode( GL_FRONT_AND_BACK, GL_SMOOTH);		//printf("Not Wireframe");		glShadeModel(GL_SMOOTH);		glCallList(objList);		glPopMatrix();		glutSwapBuffers();		glutPostRedisplay();	} 

My suggestion would be to change this code to read as follows:

if(wireframe) {
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

glCallList(objList);
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();

Doing it this way will save you some repetitive code since the only difference between the 2 if statements was whether or not to use filled polygons. Now keep in mind that I didn’t look all the way through the code, I just picked out the obvious problem. I am not sure if there is mroe wrong or not. Let us know how it goes for you. Good luck.

you can edit your own posts. Maybe you ought to fix those margins so people can see your code.

Anyone know why the margins get so freaked out :confused:

I was wondering the same thing.