Author Topic: Applet black screen  (Read 6568 times)

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Applet black screen
« on: July 08, 2008, 05:32:55 pm »
sigh....

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 );
    buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);

    // 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);
    box.setTexture("box");
    box.setEnvmapped(Object3D.ENVMAP_ENABLED);
    box.build();
    world.addObject(box);
    world.buildAllObjects();

    Camera camera = world.getCamera();
    camera.setPosition(10f,10f,10f);
    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) {
      this.repaint();
      try {
          Thread.sleep(10);
      } catch(Exception e) {
          //Don't care...
      }
    }
   
  }
 
  public void paint(Graphics g){
      buffer.clear();   // erase the previous frame
      world.renderScene( buffer );
      world.draw( buffer );
      buffer.update();
      buffer.displayGLOnly();
      canvas.repaint();    // Paint the canvas onto the applet (hardware mode)
  }

    @Override
    public void destroy()
    {
    loop=false;
    }
}

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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Applet black screen
« Reply #1 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.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Applet black screen
« Reply #2 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.

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: Applet black screen
« Reply #3 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Applet black screen
« Reply #4 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.

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: Applet black screen
« Reply #5 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Applet black screen
« Reply #6 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.