Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on September 12, 2007
-
Hello,
Is there a type of light in OpenGL that just takes direction into account and ignores distance? I would like to do this so I just need one universal light. A "sun" if you would.
I'm looking to have everything lighted with the exact same intensity. Perhaps I'm thinking about this in the wrong way.
Still fairly new to OpenGL. :)
-
That's how OpenGL lights are set by default. If the default isn't what you want, then you need to look at
glLight(GL_LIGHTi, GL_CONSTANT_ATTENUATION, ...)
glLight(GL_LIGHTi, GL_LINEAR_ATTENUATION, ...)
glLight(GL_LIGHTi, GL_QUADRATIC_ATTENUATION, ...)
Jim
-
Thanks, looks like a rotation was throwing off the position. ;)
Next question is how to set up the perspective view so that it has a 640x480 chunk of screen in the view with the "vanishing point" at x=320,y=240.
-
Here's how I set up my view for 3d
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective((CAMERA_ANGLE*SCREEN_HEIGHT)/SCREEN_WIDTH,SCREEN_WIDTH/(float)SCREEN_HEIGHT,0.125,32768.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
I have CAMERA_ANGLE=90.
That puts 0,0 in the middle of the screen, with +Y going up, +X going right, and -Z going into the screen - a very typical OpenGL view setup. It also sets nearz to 0.125 and farz to 32768.
Jim
-
Ok, I've tinkered around a bit and I'm still a bit confused.
This project has already been made and I'm switching from the standard 2d computer system to openGL for 3d graphics. I decided to do a special 3D version of the 2d game. I can't really recode all the objects movements for the coordinate system as you have shown. I did try out your code and understand it fairly well. The game is coded to move in the following view:
(0,0)___________________(640,0)
|
|
|
|
|
|
|
|
|
(0,480)---------------------(640,480)
I guess I'm just looking to emulate that view with 3D models, 320,240 being the focal point or origin of the view. Is it as simple as setting the camera postion?
-
OK, I see what you want. Replace the gluPerspective with
glOrtho(0.0, (GLdouble)SCREEN_WIDTH, (GLdouble)SCREEN_HEIGHT, 0.0, 0.0, 1.0);
That way there's no perspective calculation, the x and y are just mapped direct to screen coordinates. You might need to tinker with the near/far z values though, depending on what you're setting the z values to.
Jim