PDA

View Full Version : Polygon differentiation



Miglu
10-27-2010, 04:28 AM
I have this OpenGL initialization code:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_POINT_SMOOTH);

glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
glEnable (GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_DIFFUSE);

GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 0.0 };
GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 0.0 };
GLfloat mat_diffuse[] = { 0.0, 0.0, 1.0, 1.0 };

glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);

light_t light={
{2.0,-1.0,-2.0, 0.0},
{1.0,1.0,1,1.0},
{0,0,0,0},
{1.0,1.0,1.0,0.2}
};

glLightfv(GL_LIGHT0,GL_POSITION,light.pos);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light.diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,light.specular);
glLightfv(GL_LIGHT0,GL_AMBIENT,light.ambient);
glShadeModel (GL_SMOOTH);
The lighting works well except that it is difficult to differentiate between polygons that are in the light (not in edges, where there is shadow). For example if there is a bit sticking out of the model, it can hardly be seen when it is facing towards the "camera". I have tried different values for the material and light properties, but the problem persisted. How to solve this?

Anirban Talukdar
10-27-2010, 04:44 AM
Can you please place a sample code so that I can have a running environment setup? At least I can visualize what is happening at your end.

Thanks & Regards
Anirban Talukdar

Miglu
10-27-2010, 05:03 AM
The model is parsed from text files, so I do not have any glBegin - glEnd code that you could use, unless you want the text files and parsing code. It is a ball with a tube sticking out of it, so that it looks like a lollipop. Can you visualize it?

Anirban Talukdar
10-27-2010, 06:01 AM
Sir,

You have defined a structure for light.

light_t light={
{2.0,-1.0,-2.0, 0.0},
{1.0,1.0,1,1.0},
{0,0,0,0},
{1.0,1.0,1.0,0.2}
};

Please give an explanation for the members of the structure.

Thanks & Regards
Anirban Talukdar

Miglu
10-27-2010, 06:31 AM
typedef struct
{
float pos[4];
float diffuse[4];
float specular[4];
float ambient[4];
}light_t;

Anirban Talukdar
10-27-2010, 11:58 AM
Hi Miglu,

I believe the problem is something to do with the GL_DEPTH_TEST. Please run it with commenting the line. Also can you please send me a model file so that I can test it further. In my case only if i comment out that line i am able to see the contents.

Thanks & Regards
Anirban Talukdar

Miglu
10-28-2010, 03:17 AM
Removing glEnable(GL_DEPTH_TEST) makes the model very weird, so that is not the solution.