Hardware jpct-lwjgl Applets

Started by AGP, April 23, 2009, 12:33:47 AM

Previous topic - Next topic

AGP

I'm trying to make hardware jpct-lwjgl applets that use the joystick and 3D hardware. All three of the first ones have failed to render anything to the screen (except for when on the third one I was using jpct's software renderer). Check out the code of this incredibly simple applet and remember it worked on software rendering (without the canvas). As it is, I get a black screen (nothing renders). By the way, although I'm only using ambient light on this one, the other two had other lights positioned around the world.

import java.applet.*;
import java.awt.*;
import com.threed.jpct.*;
import com.threed.jpct.util.Light;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*; //JOYSTICK AND OPENGL-MODE KEYBOARD

public class SimpleApplet3D extends Applet implements Runnable {
      private Object3D object;
      private World theWorld;
      private FrameBuffer buffer;
      private Camera theCamera;
      private boolean keepGoing;
      private Controller joystick;
      private Canvas theCanvas;

      public void init() {
object = Loader.load3DS("c:/MyPrograms/3D/SimpleApplet/Girl.3DS", 1f)[0];
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
Config.maxPolysVisible *= 3;
theWorld = new World();
theCamera = theWorld.getCamera();
this.add(theCanvas = buffer.enableGLCanvasRenderer());
Controllers controllers = new Controllers();
try {
      controllers.create();
      if (controllers.getControllerCount() > 0) {
joystick = controllers.getController(0);
System.out.println("Got the joystick. Its name: "+joystick.getName());
      }
}
catch (org.lwjgl.LWJGLException e) {}
theWorld.addObject(object);
theWorld.setAmbientLight(65, 65, 65);
keepGoing = true;
      }
      public void start() {
Thread appletLoop = new Thread(this);
appletLoop.start();
      }
      private void draw() {
buffer.clear(Color.black);
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.display(theCanvas.getGraphics());
// buffer.displayGLOnly();
      }
      public void run() {
while (keepGoing) {
      if (joystick != null) {
theCamera.moveCamera(Camera.CAMERA_MOVEIN, joystick.getYAxisValue());
      }
      draw();
      try {
Thread.sleep(50);
      }
      catch (InterruptedException e) {}
}
      }
      public void stop() {
keepGoing = false;
      }
      public void destroy() {}
}

paulscode

#1
I don't think FrameBuffer.display( Graphics ) works when using the GLCanvasRenderer.  Try using this instead:
buffer.displayGLOnly();
theCanvas.repaint();

Also, I generally place this in the applets paint() method, but it might work fine in the draw() method where you have it (I've never tried it that way before).

--EDIT--
Actually, after reading the JavaDoc, your way should work fine too:
QuotedisplayGLOnly ... It's not required to display the OpenGL rendered image by using this method, the normal display()-method will work too, but the Graphics parameter will be ignored in this case (can even be null)

So your problem is most likely that you simply need to repaint the canvas.  Also, I don't see anywhere in your code where you are telling to applet to repaint (other than when the draw() method is naturally called).

AGP

Thanks, I always seem to get stuck on the little things. theCanvas.repaint() did it. And a little note: I wasn't polling the joystick, so if anyone is looking at this code, before joys.getYAxisValue() is called, joystick.poll() should be.

EgonOlsen

I guess i can ignore your mail then, because the problem is solved!?

AGP

Yup, I didn't want to post code, then I figured it was actually a good thing. It's a simple applet and it's nice to have a simple example to show anyone who might be starting.

fireside

There's a code snippet section in the wiki that would be a good place for it.  Things like this get buried in a short while and can be hard to search.
click here->Fireside 7 Games<-

AGP

#6
Thanks, maybe I'll change it a little bit (things like addressing the URL instead of the file) and post it there.

EDIT: Then again, I looked at the wiki and it seems that Paulscode has already put a nice example.

EgonOlsen

Quote from: AGP on April 24, 2009, 04:18:31 AM
Thanks, maybe I'll change it a little bit (things like addressing the URL instead of the file) and post it there.

EDIT: Then again, I looked at the wiki and it seems that Paulscode has already put a nice example.
Yes, but yours adds the joystick support. Just put it onto a new page under Code Snippets if you want to.

AGP

#8
Sure, will do.

EDIT: Done. And I added a bit about specifying the applet heap size via HTML. If somebody could format the whole thing so it looks right, I'd appreciate it.

EgonOlsen

#9
You've somehow destroyed the Wiki's main page... ??? I had to undo your changes and added a new page under code snippets. Just edit that one instead.

Edit: Use <pre>....</pre> to format your code. Not the Wiki's code-Tag, as it creates funny results...

AGP

#10
I'll add it again. But how did I destroy the main page? And I didn't use tags at all (other than the html tags).

EDIT: Used your <pre> tag suggestion and it looks fine now. Can you create me a new page for the html heap size suggestion?

EgonOlsen

Quote from: AGP on April 24, 2009, 09:36:46 AM
EDIT: Used your <pre> tag suggestion and it looks fine now. Can you create me a new page for the html heap size suggestion?
You can do this yourself. Just edit the Main Page and add something like [[ your page name ]], save the page, click on the link it created and edit.

AGP

#12
Living and learning. Done.

EDIT: And the Joystick Wiki is gone. Was it because I renamed it (duh!)?
EDIT: Added it again, so don't worry about it.