jPCT - a 3d engine for Java => Support => Topic started by: .jayderyu on July 08, 2008, 05:32:55 pm

Title: Applet black screen
Post by: .jayderyu on July 08, 2008, 05:32:55 pm

I've been banging my head over this a good portion last night. I've tried scouring through the support section. I've seen some information but they don't seem to work. I'm missing something obvious I'm sure. I've reduced my work to use Pauls jPCTGears demo as the basics. Can anyone point out whats wrong.

this program runs through applet loader and is in hardware.

Code: [Select]
import java.applet.*;
import javax.swing.JApplet;
import java.awt.*;

import com.threed.jpct.*;

public class Editor extends Applet implements Runnable{
  private boolean exit = false;

  private World world;
  private FrameBuffer buffer;
  private Camera camera = null;
  private int width = 640;
  private int height = 480;
  private boolean loop=true;

  Canvas canvas;
  private EditorInput input;

  public void init(){
    world = new World();
    World.setDefaultThread( Thread.currentThread() );
    world.setAmbientLight(50, 250, 50);
    world.getLights().setOverbrightLighting (Lights.OVERBRIGHT_LIGHTING_DISABLED );
    world.getLights().setRGBScale( Lights.RGB_SCALE_2X );

    world.setAmbientLight( 150, 150, 150 ); // just trying to get anything besides black screen

    // Create a main light-source:
    world.addLight( new SimpleVector( 50, -50, 300 ), 20, 20, 20 );   
    // prepare buffer
    buffer = new FrameBuffer( width, height, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY );

    // prepare canvas
    canvas = buffer.enableGLCanvasRenderer();
    add( canvas, BorderLayout.CENTER);
    canvas.setVisible( true );
    //canvas.addMouseListener( input );
    //canvas.addMouseMotionListener( input );
    TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
    //test object
    Object3D box = Primitives.getBox(3f, 2f);

    Camera camera = world.getCamera();
    camera.lookAt(new SimpleVector(0,0,0)); // look at center of world. assuming box defaults to 0.0.0
    new Thread(this).start();
  public void run() {
    while (loop) {
      try {
      } catch(Exception e) {
          //Don't care...
  public void paint(Graphics g){
      buffer.clear();   // erase the previous frame
      world.renderScene( buffer );
      world.draw( buffer );
      canvas.repaint();    // Paint the canvas onto the applet (hardware mode)

    public void destroy()

yeah this code doesn't work. The TaskManager also doesn't report much activity from Firefox or Java. Which leaves me to believe
that no real repainting is being done.
Title: Re: Applet black screen
Post by: Melssj5 on July 08, 2008, 05:59:27 pm
Are you getting any exception???, check the java console in the system tray icon and check is its something wrong.

try to put some system.out.println ("Just to check To check"); do it and post your code and your console messages again. Actually I am at work anda cant run your app.
Title: Re: Applet black screen
Post by: EgonOlsen on July 08, 2008, 06:00:46 pm
I second this. Put some printlns in paint() and such to see if it's actually getting called. Also call clear with another color than black, to see if the the applet is black because of the rendering or because of something else.
Title: Re: Applet black screen
Post by: .jayderyu on July 08, 2008, 06:51:46 pm
Thank you, thank you. I tend sometimes miss the obvious when I've been dealing with problems to long. The suggestions helped
me locate what was going on :)

I'm having IO Permission errors when trying to load textures. Not sure why that's coming up. I will need to fix that too.
Any ideas what might cause that.
Title: Re: Applet black screen
Post by: EgonOlsen on July 08, 2008, 07:30:32 pm
Maybe your textures come from a different server? Why don't you put them in a har together with your class files. That's the easiest and fastest way to download and access them from inside an applet IMHO.
Title: Re: Applet black screen
Post by: .jayderyu on July 09, 2008, 05:09:41 pm
I've put the texture in the jar file. That's where l get the IO File permission problem. I was reading up on Pauls jPCT Gears demo and there is use of a using more of a complex command for loading resources as a Input Stream. Not sure if that's normal for Applet's at all. I'm switching over from a jME webstart to jPCT Applet. I'm not familiar with Applets as much, but my project concept leans towards Applets better.

As a side note. I switched over from jME because after all the .jars and jni I would need required roughly 10mb. Where as jPCT is going to clock in at about 2mb. I just prefer my quick online game designs to be smaller. Awesome engine btw. I really like it.
Title: Re: Applet black screen
Post by: EgonOlsen on July 09, 2008, 07:18:46 pm
When loading the textures from the jar, you have to do it via an InputStream. You can't load them via a file. If that's what you are doing, try the InputStream way. That should work.

I'm glad that you like the engine. To maintain a small size is still one of its main goals.