Jump to content
  • Advertisement
Sign in to follow this  
jmaupay

OpenGL glLightModel and Forceware

This topic is 4418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I created a thread a month ago ( that thread ) and have no clue to understand that problem so if any OpenGL guru here could have a look at it, I would appreciate. In order make it more visible, here is some snapshots: Image Hosted by ImageShack.us Image Hosted by ImageShack.us The problem is the same with all recent forceware drivers (including 91.33). I think that the good result is 2 white triangles ? PM me if you need the .exe file. The glut program is :
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <iostream.h>


bool vDraw2Triangles = true ;

void display(void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glFrontFace(GL_CCW) ;
	glNormal3f(0,0,1.000000) ;
        // Remember it is ColorMaterial enabled and glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE
	glColor4f(1.000000,1.000000,1.000000,1.000000) ;

	// First face: 
	if (vDraw2Triangles)
	{
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1) ;
		glEnable(GL_CULL_FACE) ;


		glBegin(GL_TRIANGLE_STRIP) ; 
			glVertex3f(0,1,0) ;
			glVertex3f(-1,1,0) ;
			glVertex3f(-1,0,0) ;
		glEnd() ;
	}

	// Second face: back face is visible but we disable back face culling
	// not correctly drawn (black instead of white)
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0) ;
	glDisable(GL_CULL_FACE) ;

	glBegin(GL_TRIANGLES) ; 
		glVertex3f(0,0,0) ;
		glVertex3f(0,1,0) ;
		glVertex3f(1,1,0) ;
	glEnd() ;


	glutSwapBuffers() ;
	glutPostRedisplay() ;
}

void reshape (int w, int h)
{
	glViewport (0, 0, (GLsizei) w, (GLsizei) h);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity();
	if (w <= h)
	  glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
		 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
	else
	  glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
		 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
	switch (key) {
		case 27:
			exit(0);
		break;
		case 'b': case 'B' :
			vDraw2Triangles = !vDraw2Triangles ;
		break ;
	}
}



void Initialization()
{
	glClearColor (0.5, 0.6, 0.8, 0.0);

	glShadeModel(GL_SMOOTH) ;

	glEnable(GL_LIGHTING);

	glEnable(GL_LIGHT0);
	GLfloat specular[] = { 0.0, 0.0, 0.0, 0.0 };
	GLfloat ambiant[] = { 0.7, 0.7, 0.7, 1.0 };

	GLfloat lig_pos[] = { 0.0, 10., 1. };
	glLightfv(GL_LIGHT0,GL_POSITION,lig_pos) ;
	glLightfv(GL_LIGHT0,GL_AMBIENT,ambiant) ;
	glLightfv(GL_LIGHT0,GL_DIFFUSE,ambiant) ;
	glLightfv(GL_LIGHT0,GL_SPECULAR,specular) ;


	glEnable(GL_COLOR_MATERIAL) ;
	glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE) ;

}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize (1024, 768); 
	glutInitWindowPosition (0, 0);
	glutCreateWindow (argv[0]);

	Initialization() ;

	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMainLoop();
	return 0;
}


Share this post


Link to post
Share on other sites
Advertisement
Sorry to post a reply to my own message, but what I found could help someone one day ?

Well I don't have any shader in my program. I only use OpenGL 1.2 routines (or something like that). I don't have any GLSL nor CG ...

But the solution is the following:

Instead of using:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1)
use :
glEnable(GL_VERTEX_PROGRAM_TWO_SIDE);

And instead of using:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0) ;
use:
glDisable(GL_VERTEX_PROGRAM_TWO_SIDE);

And all is OK ... If someone have an explanation ...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!