C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-21-2002, 06:48 PM   #1
genghis37
Guest
 
Posts: n/a
Unhappy need help with opengl lighting!!

I just finished the chapter on lighting from the red book. So I figured id put some skillz to the test and rip out a program that modeled the solar system fairly accurately.

Well everything seemed to be going quite well. I got a window on the screen. I got opengl mapped to the window. I rendered a sphere at the origin of the screen. Now, ofcourse the sphere looked rather flat until I enabled the lighting. And so then even the lighting seemed to be working. But then I tried to position the light in various different positions and the way the sphere was being illuminated seemed rather bizarre. For example, with the modelview matrix always set to identity, i would set the light position to (0,1,0,0) and it would illuminate the sphere from the right.

Maybe im doing something stupid or maybe i really missed out on something, but i dont care cuz I really just wanna get it working. I tried to run all sorts of tests with no good results.

heres the main portion of the code:
void init()
{
glViewport(0, 0, width, height);

glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.2, 1.2, -1.2, 1.2, -1.2, 1.2);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

float pos0[4] = {0.0, 0.0, 5.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, pos0);
glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
}

bool display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

float pos0[4] = {1.2, 0.0, 0.0, 1.0};
glRotatef(angle++, 1.0, 0.0, 1.0);
glLightfv(GL_LIGHT0, GL_POSITION, pos0);
glEnable(GL_LIGHT0);

glLoadIdentity();
glPointSize(10.0);
glDisable(GL_LIGHTING);
glBegin(GL_POINTS);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(4.5, 0.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 4.5, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, 4.5);
glEnd();
glEnable(GL_LIGHTING);

glLoadIdentity();
glRotatef(angle+=0.1f, 1.0, 0.0, 0.0);
DrawSphere(5);

return true;
}
  Reply With Quote
Old 06-22-2002, 12:28 AM   #2
Registered User
 
Join Date: Jan 2002
Posts: 75
oh nm. solved the problem. very stupid. i didnt even learn anything out of it. just wasted a lot of time.
genghis is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shininess lighting GLUT OpenGL Zishaan Game Programming 1 04-22-2007 08:30 PM
OpenGL lighting Zishaan Game Programming 6 04-21-2007 03:24 PM
OpenGL lighting BabyG Game Programming 3 08-29-2004 09:58 AM
Lighting in OpenGL MathFan Game Programming 5 06-28-2004 12:56 PM
OpenGL lighting problems sirSolarius Game Programming 0 12-01-2003 09:11 PM


All times are GMT -6. The time now is 09:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22