PDA

View Full Version : glNormal(?)



12-17-2001, 11:13 AM
Hi.
I have created two textured quads to act somewhat like a floor and ceiling like this

glBegin(GL_QUADS);
//TOP QUAD
glTexCoord2f(0,0); glVertex3f( 10.0f,0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f(-10.0f,0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f(-10.0f,0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f( 10.0f,0.9f,-20.0f); //TL

//BOTTOM QUAD
glTexCoord2f(0,0); glVertex3f(-10.0f,-0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f( 10.0f,-0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f( 10.0f,-0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f(-10.0f,-0.9f,-20.0f); //TL
glEnd();

now i dont know how to set the normals for them i have tried all kind of different settings but the light just turns out wierd or everything turns black

some help would be appriciated.

Jantje
12-17-2001, 11:36 AM
This tutorial explains this precisely: http://nehe.gamedev.net/tutorials/lesson07.asp

12-17-2001, 12:03 PM
Well i have read the tutorial before and i thought i knew how to do it but i dosent work

i tohught my ceiling would have -y and the floor +y but this just turns out black

Korval
12-17-2001, 12:38 PM
Maybe you should post the lighting setup code and the rendering code with normals.

12-17-2001, 01:06 PM
//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/////////////////////////////////////
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);

//DRAW SCENE////////////////////////////////
glBegin(GL_QUADS);
//TOP QUAD
glNormal3f(0.0f,-1.0f,0.0f);
glTexCoord2f(0,0); glVertex3f( 10.0f,0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f(-10.0f,0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f(-10.0f,0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f( 10.0f,0.9f,-20.0f); //TL

//BOTTOM QUAD
glNormal3f(0.0f,1.0f,0.0f);
glTexCoord2f(0,0); glVertex3f(-10.0f,-0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f( 10.0f,-0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f( 10.0f,-0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f(-10.0f,-0.9f,-20.0f); //TL
glEnd();

12-17-2001, 11:50 PM
I just can't get it to work so i'll post more of my code to see if anyone can help me

//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,20.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,0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f(-10.0f,0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f(-10.0f,0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f( 10.0f,0.9f,-20.0f); //TL

//BOTTOM QUAD
glNormal3f(0.0f,1.0f,0.0f);
glTexCoord2f(0,0); glVertex3f(-10.0f,-0.9f, 0.0f); //BL
glTexCoord2f(1,0); glVertex3f( 10.0f,-0.9f, 0.0f); //BR
glTexCoord2f(1,1); glVertex3f( 10.0f,-0.9f,-20.0f); //TR
glTexCoord2f(0,1); glVertex3f(-10.0f,-0.9f,-20.0f); //TL
glEnd();

return TRUE;
}

Jantje
12-18-2001, 02:42 AM
Hi, are you seeing the textures when you turn
off lighting?
I tried your code and it works over here...

12-18-2001, 02:46 AM
Yes I see the textures if i turn the light off.
The light shows up(but not correct)
if i set the normals to any x or z value its real strange http://www.opengl.org/discussion_boards/ubb/frown.gif