Author Topic: [noob] my first try  (Read 2474 times)

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
[noob] my first try
« on: December 10, 2006, 06:19:03 pm »
It's my first try with this (well exactly ANY) engine and I just can't get it to work
here's the code (sorry for making another thread with "correct my code, please", I just really can't find the critial thing that makes stuff not working):
Code: [Select]
import java.io.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import com.threed.jpct.*;
import com.threed.jpct.util.*;

class Cube {

    private final static int SWITCH_RENDERER=35;
    private boolean fullscreen=false;
    private boolean openGL=true;
    private boolean wireframe=false;

    private FrameBuffer buffer=null;
    private World theWorld=null;
    private TextureManager texMan=null;
    private Camera camera=null;

    private int width=640;
    private int height=480;

    private Frame frame=null;
    private Graphics gFrame=null;
    private BufferStrategy bufferStrategy=null;
    private GraphicsDevice device=null;
    private int titleBarHeight=0;
    private int leftBorderWidth=0;

    private int switchMode=0;

    private int fps;
    private int lastFps;
    private long totalFps;

    private int pps;
    private int lastPps;

    private boolean isIdle=false;
    private boolean exit=false;

    private boolean left=false;
    private boolean right=false;
    private boolean forward=false;
    private boolean back=false;
    private boolean fire=false;
    private int fireCount=3;

    private float speed=0;

    private KeyMapper keyMapper=null;

    private Cube(String[] args) {
        Config.glFullscreen=false;
        Config.glMipmap=true;
        Config.glColorDepth=16;
        Config.maxPolysVisible=10000;
        isIdle=false;
        switchMode=0;
        totalFps=0;
        fps=0;
        lastFps=0;
        theWorld=new World();
        texMan=TextureManager.getInstance();
        Config.fadeoutLight=false;
        theWorld.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
        theWorld.getLights().setRGBScale(Lights.RGB_SCALE_2X);
        theWorld.setAmbientLight(25, 30, 30);
        theWorld.addLight(new SimpleVector(0, -150, 0), 25, 22, 19);
        theWorld.addLight(new SimpleVector(-1000, -150, 1000), 22, 5, 4);
        theWorld.addLight(new SimpleVector(1000, -150, -1000), 4, 2, 22);
        theWorld.setFogging(World.FOGGING_ENABLED);
        theWorld.setFogParameters(1200, 0, 0, 0);
        Config.farPlane=1200;
        Object3D cube = Primitives.getBox(10, 1);
        cube.setOrigin(new SimpleVector(0, 0, 0));
        char c=File.separatorChar;
        texMan.addTexture("tekstura", new Texture("textures"+c+"ql0.jpg"));
        cube.setTexture("tekstura");
        cube.setTranslationMatrix(new Matrix());
        theWorld.addObject(cube);
        camera=theWorld.getCamera();
        camera.setPosition(0, 0, -180);
        camera.lookAt(cube.getTransformedCenter());

        theWorld.buildAllObjects();
        Config.tuneForOutdoor();
        initializeFrame();
        gameLoop();
    }

    public static void main(String[] args) {
        new Cube(args);
    }

    private void initializeFrame() {
        if (fullscreen) {
            GraphicsEnvironment env=GraphicsEnvironment.getLocalGraphicsEnvironment();
            device=env.getDefaultScreenDevice();
            GraphicsConfiguration gc=device.getDefaultConfiguration();
            frame=new Frame(gc);
            frame.setUndecorated(true);
            frame.setIgnoreRepaint(true);
            device.setFullScreenWindow(frame);
            if (device.isDisplayChangeSupported()) {
                device.setDisplayMode(new DisplayMode(width, height, 32, 0));
            }
            frame.createBufferStrategy(2);
            bufferStrategy=frame.getBufferStrategy();
            Graphics g=bufferStrategy.getDrawGraphics();
            bufferStrategy.show();
            g.dispose();
        } else {
            frame=new Frame("jPCT "+Config.getVersion());
            frame.pack();
            Insets insets = frame.getInsets();
            titleBarHeight=insets.top;
            leftBorderWidth=insets.left;
            frame.setSize(width+leftBorderWidth+insets.right, height+titleBarHeight+insets.bottom);
            frame.setResizable(false);
            frame.show();
            gFrame=frame.getGraphics();
        }
        frame.addWindowListener(new WindowEvents());
        keyMapper=new KeyMapper(frame);
    }

    private void gameLoop() {
        World.setDefaultThread(Thread.currentThread());
        buffer=new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
        buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
        buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);
        buffer.optimizeBufferAccess();

        Timer timer = new Timer(25);
        timer.start();

        while(!exit) {
            if(!isIdle) {
                buffer.clear();
                theWorld.renderScene(buffer);
                theWorld.draw(buffer);
                buffer.update();
                buffer.display(gFrame, height, width);
                Thread.yield();
            }
        }
        if (openGL) {
            buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
        } else {
            if (fullscreen) {
                device.setFullScreenWindow(null);
            }
        }
        System.exit(0);
    }

    private class WindowEvents extends WindowAdapter {
        public void windowIconified(WindowEvent e) {
            isIdle=true;
        }

        public void windowDeiconified(WindowEvent e) {
            isIdle=false;
        }
    }

    private class Timer {

        private long ticks=0;
        private long granularity=0;

        public Timer(int granularity) {
            this.granularity=granularity;
        }

        public void start() {
            ticks=System.currentTimeMillis();
        }

        public void reset() {
            start();
        }

        public long getElapsedTicks() {
            long cur=System.currentTimeMillis();
            long l=cur-ticks;

            if (l>=granularity) {
                ticks=cur-(l%granularity);
                return l/granularity;
            }
            return 0;
        }
    }

}


all I see is a white window with no box

Offline theFALCO

  • byte
  • *
  • Posts: 39
    • View Profile
[noob] my first try
« Reply #1 on: December 11, 2006, 08:27:08 pm »
okay, I found it, it was a silly one:
Code: [Select]
buffer.display(gFrame, height, width);
is wrong
Code: [Select]
buffer.display(gFrame, leftBorderWidth, titleBarHeight);
is correct
 :oops:
sorry for spam

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
[noob] my first try
« Reply #2 on: December 12, 2006, 03:56:33 pm »
^^;

Atleast you solved your own problem! I saw this post, and I did not know where to begin looking in the code...