Smooth/Flat shading and Wireframe

Hello.

I’m only one month into OpenGL and i have a question. This may be very basic and nooby, but i haven’t find the correct answer as of yet :frowning:

We are working on an exercise, and one part is to allow for 3 visualisations: flat shaded, smooth shaded, and wireframe.

I’ll start by showing the code i got untill now:

if ( m_polygonMode == FLATSHADING )
	{
		glEnable(GL_FLAT);
		glShadeModel(GL_FLAT);
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
	}
	else if ( m_polygonMode == SMOOTHSHADING )
	{
		glEnable(GL_SMOOTH);
		glShadeModel(GL_SMOOTH);
		glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
	}
	else if ( m_polygonMode == WIREFRAME )
	{
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}

The last if test gives me a wonderful Wireframe mode. Tho there is no difference between the first two if testes; they both seem to be “smooth shaded”.

Thanks a lot for your help and time =)

Bart

stick a glGetError() call into your app

cause youll find these are invalid
glEnable(GL_FLAT);
glEnable(GL_SMOOTH);

have u supplied normals (or something similar) for your models?
if u havent u wont see any difference

No i haven’t. How do i supply those? I’ve already read something about having to calculcate them for every surface (how can one calculate those for 30300294 surfaces? :/) but then how does one “supply” them?

“how can one calculate those for 30300294 surfaces?”

By using a computer :wink:

Google should give you a formula for calculating a normal from 3 vertices (actually it is: normalize (cross (v3 - v2, v1 - v2))).

You supply your normal using glNormal3f if you are using immediate mode.

But that will only give you flat-shaded polys, if all vertices of a face use the same plane-normal. You will need to smooth the normals of the vertices. Usually by adding all face-normals that touch the same vertex and then re-normalizing it. Depends on what exactly you want. There are countless other ways to generate smooth normals.

Hope that gives you some pointers,
Jan.