![]() |
| | #1 |
| Guest
Posts: n/a
| 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; } |
|
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |