Sign in to follow this  
renegat

OpenGL glLightModel two sieded lighting

Recommended Posts

I've got question concerning lighting in opengl. After loading vertexes,normals,texcoords etc. from obj I'm trying to make the model being two sided, but somehow it doesn't work. I added to my program: glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,true); (on one sided everything works as it should, when two sided model is enlightned only sometimes and not correctly). I've changed parameters of material via glDiffuse(1,1,1); int glDiffuse(float r,float g,float b,float z=1) { float mat[4]; mat[0] = r; mat[1] = g; mat[2] = b; mat[3] = z; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat); } It looks like as if the model was enlightned from behind... (not from the direction of the viewer) [Edited by - renegat on September 28, 2006 3:24:15 AM]

Share this post


Link to post
Share on other sites
Try calling glFrontFace(GL_CW) and glFrontFace(GL_CCW) (separately) and see if either one fixes your problem. It might just be that the polygons are facing the wrong way relative to the viewport.

Share this post


Link to post
Share on other sites
Well yeah I thought of that. It doesn't work with GL_CW, it doesn't work with GL_CCW...

I put my program on the web, but I don't know if that will help. Some parts of it are written in Polish language.
http://rapidshare.de/files/34803188/program.rar.html

I read obj file via obj.h module, opengl functions are in the opgl.h

Share this post


Link to post
Share on other sites
static float lmodel_twoside[] =
{GL_TRUE};
static float lmodel_oneside[] =
{GL_FALSE};

void
initLightAndMaterial(void)
{
static float diffuse[] =
{0.5, 1.0, 1.0, 1.0};
static float position[] =
{90.0, 90.0, 150.0, 0.0};

static float front_mat_diffuse[] =
{1, 0, 0, 1.0};
static float back_mat_diffuse[] =
{0.0, 1, 0, 1.0};

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);

glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);

glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

int InitGL(GLvoid) {
initLightAndMaterial();
glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return TRUE;
}

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,z);

glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);

glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();

xrot+=xspeed;
yrot+=yspeed;
return TRUE; }

It is changed lesson7 from nehe. I push the left arrow key, the quad rotates and when we should be able to see green quad, screen becomes black. Only on the end of rotation quad becomes for a moment green. What do I do wrong? Something is messed up with normals?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this