Author Topic: Hardware jpct-lwjgl Applets  (Read 6322 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Hardware jpct-lwjgl Applets
« on: April 23, 2009, 12:33:47 am »
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.

Code: [Select]
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() {}
}

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Hardware jpct-lwjgl Applets
« Reply #1 on: April 23, 2009, 01:26:39 am »
I don't think FrameBuffer.display( Graphics ) works when using the GLCanvasRenderer.  Try using this instead:
Code: [Select]
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:
Quote
displayGLOnly ... 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).
« Last Edit: April 23, 2009, 01:38:02 am by paulscode »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #2 on: April 23, 2009, 05:39:59 am »
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
Code: [Select]
joys.getYAxisValue() is called,
Code: [Select]
joystick.poll() should be.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Hardware jpct-lwjgl Applets
« Reply #3 on: April 23, 2009, 07:56:45 am »
I guess i can ignore your mail then, because the problem is solved!?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #4 on: April 23, 2009, 09:01:35 am »
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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #5 on: April 23, 2009, 02:13:08 pm »
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<-

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #6 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.
« Last Edit: April 24, 2009, 05:36:49 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Hardware jpct-lwjgl Applets
« Reply #7 on: April 24, 2009, 07:40:37 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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #8 on: April 24, 2009, 08:07:40 am »
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.
« Last Edit: April 24, 2009, 08:45:41 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Hardware jpct-lwjgl Applets
« Reply #9 on: April 24, 2009, 08:57:30 am »
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...
« Last Edit: April 24, 2009, 09:00:48 am by EgonOlsen »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #10 on: April 24, 2009, 09:36:46 am »
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?
« Last Edit: April 24, 2009, 09:42:06 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Hardware jpct-lwjgl Applets
« Reply #11 on: April 24, 2009, 10:19:58 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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Hardware jpct-lwjgl Applets
« Reply #12 on: April 24, 2009, 10:29:39 am »
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.
« Last Edit: April 24, 2009, 10:38:18 am by AGP »