Author Topic: Stupid noob question...  (Read 2602 times)

Offline WTH

  • byte
  • *
  • Posts: 4
    • View Profile
Stupid noob question...
« on: September 30, 2009, 06:57:05 pm »
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:

Code: [Select]
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
« Last Edit: September 30, 2009, 06:58:37 pm by WTH »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Stupid noob question...
« Reply #1 on: September 30, 2009, 08:05:43 pm »
Try to override update(Graphics g) and let it call paint(g).

Offline WTH

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Stupid noob question...
« Reply #2 on: September 30, 2009, 11:19:37 pm »
That was just absolutely insightful and helpful m8, cheers  ;D.  I guess I'll need to start looking into Applets more.