PDA

View Full Version : Lighting problems (smooth shading)



ken84shin
01-04-2010, 02:51 AM
Hi,

I'v load a object from an object file,
I used to work on wire frame mode and now I want it to have smooth shading.
But, I can't manage to do it.My object now still looks like its having flat shading.For example: a top view of a teapot makes it looks 2D.Cant see the outline of the teapot cover.
Do not know where the problem lies.
Heres a portion the code.



float mat_specular[]={1.0f, 1.0f, 1.0f, 1.0f};
float mat_shininess[]={50.0f};
float light_position[]={-2.0f, -3.0f, 4.0f, 0.0f};
float white_light[]={1.0f, 1.0f, 1.0f, 1.0f};
float lmodel_ambient[]={0.1f, 0.1f, 0.1f, 1.0f};

//gl.glEnable(gl.GL_NORMAL_ARRAY);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Set smooth shading mode for drawing the object
gl.glShadeModel(gl.GL_SMOOTH);
gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, mat_specular,0);
gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS,mat_shininess,0);

gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 0);
gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, white_light, 1);
gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, white_light, 1);
gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient,2);

gl.glEnable(gl.GL_LIGHTING);
gl.glEnable(gl.GL_LIGHT0);
gl.glEnable(gl.GL_DEPTH_TEST);
gl.glEnable(gl.GL_COLOR_MATERIAL);



I then draw the model is the display() method.



//draw the model
drawModel(gl,drawable,gl.GL_RENDER);



Thanks for the help.

Oliver Demetz
01-04-2010, 03:23 AM
Basic question: Did you specify the normals of your teapot?

ken84shin
01-05-2010, 01:30 AM
hm..
What do you mean by specify normal?
Sorry I am not fermiliar with the terms..
but I think I have a normal array or something..