PDA

View Full Version : Coloring a 3D model loaded from .obj file



DeadCell
10-22-2009, 02:05 PM
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

glColour3f(1,0,0);

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.

thankyou

ZbuffeR
10-22-2009, 04:07 PM
"need to do this without using GL_TRIANGLES"
But why ???

MaxH
10-22-2009, 06:34 PM
... 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. 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?

thinks
10-24-2009, 02:16 PM
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 (http://csserver.ucd.ie/~thinks), for some cool techniques on how to render wireframe and solid together.

dletozeun
10-25-2009, 03:13 AM
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:
http://www.lighthouse3d.com/opengl/glsl/

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.