Author Topic: Newbie lighting question  (Read 4074 times)

Offline FireBorn

  • byte
  • *
  • Posts: 4
    • View Profile
Newbie lighting question
« on: February 17, 2009, 02:50:20 am »
Hi guys,

I'm trying to create a game using software mode rendering, as I understand using hardware mode pops up a security warning (am I right?), and I don't want to impose on the user.

The problem I'm having is I create a light source but no lighting is applied. The applet is just black. Using ambient light works fine (uncommenting that setAmbientLight() line would show all the objects correctly), so I know lighting works to some degree. Here's the code in the constructor:

Code: [Select]
world = new World();
World.setDefaultThread(Thread.currentThread());
frameBuffer = new FrameBuffer(GravityBallApplet.width, GravityBallApplet.height, FrameBuffer.SAMPLINGMODE_NORMAL);

world.addObject(interceptor.threeDee);
camera = world.getCamera();
cameraDistance = DEFAULT_CAMERA_DISTANCE;
camera.setPosition(0, 0, -cameraDistance);
world.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
//world.setAmbientLight(50, 50, 50);
world.addLight(new SimpleVector(0, 0, -1000), 20, 20, 20);

And here's the code in paint(Graphics g):

Code: [Select]
frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.update();
frameBuffer.display(g);

I've tried various positions of the light and none worked. Right now it's positioned where the camera is. Any help is much appreciated :) Thanks.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Newbie lighting question
« Reply #1 on: February 17, 2009, 03:37:37 am »
I am certainly no expert, but I can explain how I usually set up the lighting for a scene.  The first thing is, I always have some amount of ambient light in the scene just so polys aren't so dark when they aren't pointed directly toward a point-source (althought I doubt it is a requirement to have an ambient light source).  Then for the point-sources, I play around with their "brightness" (have you tried something brighter than 20, 20, 20?).  The problem might have something to do with the distance of the light source, its brightness, and the color of the objects in the scene.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Newbie lighting question
« Reply #2 on: February 17, 2009, 07:59:52 am »
Code: [Select]
world.addLight(new SimpleVector(0, 0, -1000), 20, 20, 20);...-1000 seems to be a bit too far away. Play around with this and, as Paul suggested, set some ambient light to see if there's actually something there.

Offline FireBorn

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Newbie lighting question
« Reply #3 on: February 17, 2009, 06:42:47 pm »
Thanks guys, that helped. I also had to turn off Config.fadeoutLight to get the desired effect.

I have another question. Is it possible to give the user the option to change the rendering mode to hardware from within the applet?

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Newbie lighting question
« Reply #4 on: February 17, 2009, 09:11:12 pm »
Is it possible to give the user the option to change the rendering mode to hardware from within the applet?

Yes it is pretty simple to do.  I have an example applet that does switching between software and hardware rendering modes - you can download it from this thread.  Note that it will require your applet to be loaded via the applet loader whether or not the user decides to use hardware rendering or not (i.e. the first time users load your applet, they will get the message asking if they trust the digital signature).  If that is a problem, you could create two seperate applets instead (one software rendering mode, one hardware rendering mode), and either create two different links, or switch between the two applets via javascript.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Newbie lighting question
« Reply #5 on: February 18, 2009, 02:09:38 am »
In my opinion, it's better to have two different apps.  Hardware requires an extra 1.5 meg download and why do that to someone that isn't going to use it?
click here->Fireside 7 Games<-