Author Topic: Light in OpenGL that ignores distance.  (Read 3462 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Light in OpenGL that ignores distance.
« 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. :)
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Light in OpenGL that ignores distance.
« Reply #1 on: September 12, 2007 »
That's how OpenGL lights are set by default.  If the default isn't what you want, then you need to look at
Code: [Select]
glLight(GL_LIGHTi, GL_CONSTANT_ATTENUATION, ...)
glLight(GL_LIGHTi, GL_LINEAR_ATTENUATION, ...)
glLight(GL_LIGHTi, GL_QUADRATIC_ATTENUATION, ...)

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Light in OpenGL that ignores distance.
« Reply #2 on: September 13, 2007 »
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.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Light in OpenGL that ignores distance.
« Reply #3 on: September 13, 2007 »
Here's how I set up my view for 3d
Code: [Select]
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
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Light in OpenGL that ignores distance.
« Reply #4 on: September 16, 2007 »
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?
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Light in OpenGL that ignores distance.
« Reply #5 on: September 16, 2007 »
OK, I see what you want.  Replace the  gluPerspective with
Code: [Select]
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
« Last Edit: September 16, 2007 by Jim »
Challenge Trophies Won: