Newbie lighting question

Started by FireBorn, February 17, 2009, 02:50:20 AM

Previous topic - Next topic

FireBorn

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:


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):


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.

paulscode

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.

EgonOlsen

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.

FireBorn

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?

paulscode

Quote from: FireBorn on February 17, 2009, 06:42:47 PMIs 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.

fireside

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<-