PDA

View Full Version : glNormal(?)

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

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

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, 10:36 AM
This tutorial explains this precisely: http://nehe.gamedev.net/tutorials/lesson07.asp

12-17-2001, 11:03 AM
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, 11:38 AM
Maybe you should post the lighting setup code and the rendering code with normals.

12-17-2001, 12: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);

//DRAW SCENE////////////////////////////////
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

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, 10: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);

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

glMatrixMode(GL_MODELVIEW);

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);

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);

glBindTexture(GL_TEXTURE_2D,Texture[0]);

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

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, 01: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, 01: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