Advertisement

Light problems

Started by December 20, 2001 03:54 PM
1 comment, last by Load Runner 23 years, 2 months ago
Hi. I have this annoying problem, I have created 2 textured quads to act somewhat like a floor and ceiling, everything works fine until I add lighting then the quads wont show up, I have tried to add other objects to my scene and they turn up just fine so I have no clue what could be the problem. heres some of my code:
    
//GLOBALS

float LightAmbient[] =  {0.5f, 0.5f, 0.5f, 1.0f};
float LightDiffuse[] =  {1.0f, 1.0f, 1.0f, 1.0f};
float LightPosition[] = {0.0f, 0.0f, 1.0f, 1.0f};

//INITGL

int InitGL(int w,int h)
{

	glViewport(0, 0, w, h);

	glClearColor(0.0f,0.0f,0.0f,0.5f);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f,(float)w/(float)h,1.0,100.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	LoadGLTextures();
	glEnable(GL_TEXTURE_2D);

	glLightfv(GL_LIGHT1,GL_AMBIENT,LightAmbient);
	glLightfv(GL_LIGHT1,GL_DIFFUSE,LightDiffuse);
	glLightfv(GL_LIGHT1,GL_POSITION,LightPosition);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHTING);
	glShadeModel(GL_SMOOTH);

	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

	return TRUE;
}

//RENDERSCENE

int RenderGLScene()
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glBindTexture(GL_TEXTURE_2D,Texture[0]);

	glBegin(GL_QUADS);
	//TOP QUAD

	glNormal3f(0.0f,-1.0f,0.0f);
	glTexCoord2f(0,0); glVertex3f( 10.0f,1.0f, 0.0f);  //BL

	glTexCoord2f(1,0); glVertex3f(-10.0f,1.0f, 0.0f);  //BR

	glTexCoord2f(1,1); glVertex3f(-10.0f,1.0f,-20.0f); //TR

	glTexCoord2f(0,1); glVertex3f( 10.0f,1.0f,-20.0f); //TL


	//BOTTOM QUAD

	glNormal3f(0.0f,1.0f,0.0f);
	glTexCoord2f(0,0); glVertex3f(-10.0f,-1.0f, 0.0f);  //BL

	glTexCoord2f(1,0); glVertex3f( 10.0f,-1.0f, 0.0f);  //BR

	glTexCoord2f(1,1); glVertex3f( 10.0f,-1.0f,-20.0f); //TR

	glTexCoord2f(0,1); glVertex3f(-10.0f,-1.0f,-20.0f); //TL

	glEnd();

	return TRUE;
}
    
I hope this is just some newbie error and that i can get it out of the way as fast as possible! thanks in advance Edited by - Load Runner on December 20, 2001 4:58:50 PM
Romance is dead,it was bougth by Disney and Hallmark and sold to the public in small portions.
I havent messed with lighting a whole lot yet, but when you declare the lights position:

float LightPosition[] = {0.0f, 0.0f, 1.0f, 1.0f};

the fourth parameter tells whether the light is directional or positional. A 0.0f means it is directional (like the sun), and anything else means it is positional, so try declaring the lights direction as well. Try changing the fourth parameter to 0.0f and see if it lights up both the ceiling and the floor.

I''m not sure if it will light them both up, but worth a try.
Advertisement
That might have been a confusing way to say it so here it goes again.

First change the 4th value to 0.0f, if that doesnt work, change it back to 1.0f and declare a direction for the light

This topic is closed to new replies.

Advertisement