Nala-Naj
Need help as I am stuck on this. Tried to get Spag and JME working following your code. I made the following assumptions:
JME handles the rendering for both JME and Spag
Spags rendering happens inside the render method of the JME
We do all the rendering in the JME’s render method (the main rendering loop)
Then cretaed a dialog in created a dialog in the createWin(), which was initiated in the initGame() and the usual setting of the mouse and keyboard - see code below:
import org.lwjgl.Display;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.vector.Vector3f;
import java.io.FileInputStream;
import com.shavenpuppy.jglib.Resources;
import com.shavenpuppy.jglib.AbsMouse;
import com.shavenpuppy.jglib.sprites.SpriteImage;
import net.puppygames.gui.*;
import jme.controller.*;
import jme.system.*;
import jme.locale.*;
import jme.AbstractGame;
import jme.system.DisplaySystem;
import jme.geometry.hud.text.Font2D;
import jme.utility.*;
import jme.texture.*;
import jme.geometry.primitive.*;
import jme.entity.*;
import jme.entity.camera.*;
import jme.entity.effects.*;
import jme.world.World;
import jme.geometry.hud.*;
import jme.locale.external.data.*;
import jme.locale.external.*;
import jme.lighting.*;
import jme.locale.external.feature.*;
import jme.math.*;
import jme.geometry.*;
import jme.geometry.model.ms.MilkshapeModel;
public class SpagTest04 extends AbstractGame {
private SimpleLocale myLocale = null;
private Font2D font;
private Timer timer = null;
Entity e7 = null;
private World world = null;
private Camera camera;
private TestController cc;
/**
* The width of the screen or window.
*/
private static int width = 640;
/**
* The height of the screen or window.
*/
private static int height = 480;
//SPG
// private net.puppygames.gui.Window w = null;
private net.puppygames.gui.Dialog w = null;
private static boolean finished = false;
public void createWin()
{
try
{
Resources.load(new FileInputStream("resources.data"));
Resources.manage();
} catch (Exception e)
{}
// w = new net.puppygames.gui.Window("map at a glance");
// w.setLocation(0, 0);
w = new net.puppygames.gui.Dialog("map at a glance");
w.centre();
w.setSize(250, 250);
// TextArea text = new TextArea("This is where a scaled down version of the map will go. The mouse cursor will turn into a box and allow you to quickly jump to anywhere on the map.");
// text.setSize(230, 200);
// text.setLocation(15, 80);
// w.addChild(text);
w.open();
}
public static void main(String[] args)
{
SpagTest04 app = new SpagTest04();
app.start();
}
public SpagTest04()
{
font = null;
camera = null;
cc = null;
}
protected void update()
{
if(!cc.update(timer.getFrameRate()))
finish();
world.update(10F / timer.getFrameRate());
timer.update();
}
protected void render()
{
GL.glClear(16640);
GL.glLoadIdentity();
cc.render(); //render after each key/mouse movement
world.render(); //render entities & then locale
//SPG
AbsMouse.poll();
Keyboard.poll();
Keyboard.read();
mainLoop();
Interface.tick();
Interface.render();
org.lwjgl.opengl.Window.update();
org.lwjgl.opengl.Window.paint();
}
private void initCamera()
{
.............
.............
}
protected void initDisplay()
{
//create the window
DisplaySystem.createDisplaySystem(640,480,16,60,false,"GameTest");
}
protected void initGL()
{
GL.glShadeModel(7425);
//Define the clear color
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL.glClearDepth(1.0D);
GL.glEnable(2929);
GL.glDepthFunc(GL.GL_LEQUAL);
GL.glMatrixMode(5889);
GL.glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(
45.0f,
(float)Display.getWidth() / (float)Display.getHeight(),
0.01f,
750.0f);
GL.glMatrixMode(5888);
GL.glHint(3152, 4354);
GL.glBlendFunc(770, 1);
DisplaySystem.getDisplaySystem().cullMode(1029, true);
}
protected void reinit()
{
Keyboard.destroy();
Mouse.destroy();
try
{
Keyboard.create();
Mouse.create();
initGL();
initTimer();
font = new Font2D("font.png");
}
catch(Exception e)
{
e.printStackTrace();
}
//SPG
try
{
Interface.init(width, height, width, height);
} catch(Exception e)
{}
}
protected void initSystem()
{
initDisplay();
initGL();
initCamera();
initTimer();
//SPG
try
{
Interface.init(width, height, width, height);
} catch(Exception e)
{}
try
{
Mouse.create();
AbsMouse.setSensitivity(8);
AbsMouse.setSize(width, height);
AbsMouse.setPosition(width / 2, height / 2);
Keyboard.create();
Keyboard.enableBuffer();
} catch(Exception e)
{}
}
protected void initGame()
{
.............
.............
createWin();
}
private void initTimer()
{
timer = Timer.getTimer();
}
protected void cleanup()
{
.............
.............
}
private final static void mainLoop()
{
processMouse();
processKeyboard();
processWindow();
}
/**
* Process keyboard events.
*/
private final static void processKeyboard()
{
.............
.............
}
/**
* Process mouse events.
*/
private final static void processMouse()
{
.............
.............
}
/**
* Process window events.
*/
private final static void processWindow() {
if (org.lwjgl.opengl.Window.isCloseRequested()) {
finished = true;
}
}
}
and compiled the code. When I run it I get :
java.lang.ArithmeticException: / by zero
at net.puppygames.gui.Component.render(Component.java:1259)
at net.puppygames.gui.Interface.render(Interface.java:570)
at SpagTest04.render(SpagTest04.java:126)
at jme.AbstractGame.start(Unknown Source)
at SpagTest04.main(SpagTest04.java:94)
java.lang.NullPointerException
at net.puppygames.gui.Interface.render(Interface.java:576)
at SpagTest04.render(SpagTest04.java:126)
at jme.AbstractGame.start(Unknown Source)
at SpagTest04.main(SpagTest04.java:94)
I am not sure what is going on and I am not even sure if I am doing the right thing.
Any idea what is going on :(