Skip to main content
gamedev.net
🔒 Locked

OpenGL lightning problem

Started by Burning_Ice 4 replies 200+ views
Original Post
Burning_Ice
Burning_Ice
Hi i got a really weird problem with OpenGL lightning: at the beginning of my prog i init a light this way: GLfloat Light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat LightPosition[] = { 0.0f, 0.0f, 50.0f, 0.0f }; glLightfv ( GL_LIGHT0, GL_SPECULAR, Light ); glLightfv ( GL_LIGHT0, GL_DIFFUSE, Light ); glLightfv ( GL_LIGHT0, GL_AMBIENT, Light ); glLightfv ( GL_LIGHT0, GL_POSITION, LightPosition ); glEnable ( GL_LIGHT0 ); glEnable ( GL_LIGHTING ); in the rendering loop i call then glRotatef for the x, y and z angles and glTranslatef with the negative position vector of my camera and then i draw my terrain as a grid of verts on the x-z plane and y as the height, from x/z -10/-10 to +10/+10 or something like that, so that the (0,0,0)-coord is in the middle of my terrain this works all the way it should, BUT the stoopid light won''t work =( In my opinion the way i do it it should just enlighten my terrain uniformly, with the lightsource 50 units above the middle of my terrain...but what i get is this: when i look in the -z direction it looks bright the way i want it, but when i turn to look in +z direction it turns completely dark it does this no matter on what point of the map the camera is and i have no idea how to get it so that the whole terrain, no matter in what direction i look, is equally lit If anyone has an idea how to solve this problem please tell me..this stuff is driving me crazy =) Thanks for your help, BurningIce
Burning_Ice
Burning_Ice
sorry, there was a typo: its
GLfloat LightPosition[] = { 0.0f, 50.0f, 0.0f, 0.0f };

but the effect of the getting darker and brighter is about the same even if i cange the z and y coord of the light...

and another thing:
when i''m directly above my terrain ( like (0,50,0) at the same spot as the light) and i''m looking down on my terrain and cycling around then so that my square terrain is rotating around the z axis from my viewpoint it is completely bright first, and gets completely dark when i roateted 180° and goes bright again when i come to 360°

as i said, its driving me crazy =)
zedzeek
zedzeek
the faq is here look under lighting http://www.frii.com/~martz/oglfaq/
maybe try GLfloat LightPosition[] = { 0.0f, 50.0f, 0.0f, 1.0f };
for a directional light

http://members.xoom.com/myBollux
WhatEver
WhatEver
Did you calculate your normals and feed them in when you draw your polys? If you don''t use normals, you''ll get the effect you speak of.
Burning_Ice
Burning_Ice
well i made a routine to calc the normals and now it looks ok

only thing that confused me was that when i drawed the terrain in x-y plane then it worked

Thanks for your help
Dave007
Dave007
The 1st think are normals
and socond is

glEnable(GL_COLOR_MATERIAL);



Dave007
dave007@volny.cz
--------Dave[ Math Studio ] A Computer Algebra System

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.