Stupid noob question...

Started by WTH, September 30, 2009, 06:57:05 PM

Previous topic - Next topic

WTH

I've taken a very simple sample applet I found on the forums here, using software rendering, and running it with JPCT and I am getting periodic serious flickering.  The clear color is black, the object is green, and everything appears as it should for about 5 seconds, then it flickers between black and white for about 1 second and returns about 5 seconds later - ad infinitum.  BTW, I am using Applet, not JApplet, as I need to build something that runs on 1.1.

The code I'm using is posted below:


import java.applet.*;
import java.awt.Graphics;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.World;

public class TestApplet extends Applet implements Runnable
{
private static final long serialVersionUID = 1L;
   private Object3D box;

   private FrameBuffer buffer = null;
   private World world = null;

   private boolean alive = true;
   private boolean initialized = false;

   // Initialize all components of the applet
   public void init()
   {
       world = new World();
       World.setDefaultThread( Thread.currentThread() );
       world.setAmbientLight( 0, 255, 0 );

       buffer = new FrameBuffer( getWidth(), getHeight(), FrameBuffer.SAMPLINGMODE_NORMAL );
       buffer.enableRenderer( IRenderer.RENDERER_SOFTWARE );

       box = Primitives.getBox( 12.0f, 2.0f );
       box.setName( "MySphere" );
       box.build();
       world.addObject( box );

       world.getCamera().setPosition( 50, -50, -50 );
       world.getCamera().lookAt( box.getTransformedCenter() );

       initialized = true;

       new Thread( this ).start();
   }

   // Main Game Loop:
   public void run()
   {
       while( alive )
       {
           box.rotateY( 0.01f );
           this.repaint();

           try
           {
               Thread.sleep( 10 );
           }
           catch( Exception e )
           {}
       }
   }

   // Draw the scene:
   public void paint( Graphics g )
   {
       if( !initialized )
           return;

       buffer.clear();

       // render the world onto the buffer:
       world.renderScene( buffer );
       world.draw( buffer );
       buffer.update();
       buffer.display( g, 0, 0 );
   }

   // End the main game loop:
   public void destroy()
   {
    alive = false;
   }
}


I'm not experienced with applets, so I'm probably doing something terrifically noobish (and if so, I apologize), but should I be manually double buffering something?  Or, am I using something obviously wrong?

Very much appreciated - btw, I'm testing on Vista SP2, with 1.6 JDK (configured to use 1.3 but emit 1.1 code) - Eclipse IDE

EgonOlsen

Try to override update(Graphics g) and let it call paint(g).

WTH

That was just absolutely insightful and helpful m8, cheers  ;D.  I guess I'll need to start looking into Applets more.