Coloring a 3D model loaded from .obj file

Hey guys, I’m a beginner at Opengl, and would appreciate some help regarding the following problem.

I have loaded a 3D model of a bowl(the sort you use for cereal), into opengl from an obj file which contains the vertices, normals, faces etc.

I have used glBegin(GL_LINES) to connect the vertices to one another, and therefore I have a model which appears like a wireframe.

I need to colour the model and then implement phong shading.

I know its easy to colour the model by just adding the the following code before glBegin


and then changing GL_LINES to GL_TRIANGLES. However I need to do this without using GL_TRIANGLES. I need to colour each pixel within the faces some other way. I am able to colour the vertices through which the lines are connected, but i need to colour the entire area/face enclosed by the lines.

Any idea how this can be done?

any advice will be highly appreciated.


“need to do this without using GL_TRIANGLES”
But why ???

Sounds like you are almost writing a scanline renderer from scratch. Are you sure this is necessary? What are you going to do about hidden surfaces?

It does indeed sound like you have been asked to write a scan line renderer from scratch. This appears a little strange since you are also using OpenGL, which does all that for you, if you want.

However, seeing as you will need to write a shader anyway for the Phong shading, since it is done per pixel, you might want to take a look at here, for some cool techniques on how to render wireframe and solid together.

Scanline renderer?? IMO, he poorly expressed what he wants to do and doesn’t know the concept of fragment shader.

DeadCell, as you seem to understand, OpenGL fixed pipeline performs Gouraud shading on triangles and it is quite ugly. To override the default shading method, you have to write your own “fragment shader”. This kind of shader operates on each pixel of the screen for which you can perform your own shading depending on various data, like fragment normal, texture coordinates, etc…

There are several shading languages supported by OpenGL that are GLSL or Cg. These languages are C-like and easy to learn.
Take a look to this glsl tutorial where you can find an example of Blinn-Phong shader:

With a fragment shader you would still need the calls to glBegin/glEnd with GL_TRIANGLE parameter. These commands just specify the vertex data in immediate mode and are not related to the shading process at all.