Simple example with Nifty
Posted by
elect on
Nov 08, 2013; 10:30am
URL: https://forum.jogamp.org/Simple-example-with-Nifty-tp4030529.html
Hi, I am trying to get a simple example with Nifty working, but I can't
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import com.jogamp.opengl.util.FPSAnimator;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.batch.BatchRenderDevice;
import de.lessvoid.nifty.nulldevice.NullSoundDevice;
import de.lessvoid.nifty.renderer.jogl.input.JoglInputSystem;
import de.lessvoid.nifty.renderer.jogl.render.batch.JoglBatchRenderBackendCoreProfile;
import de.lessvoid.nifty.spi.render.RenderDevice;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import de.lessvoid.nifty.spi.time.TimeProvider;
/**
*
* @author gbarbieri
*/
public class Test2 implements GLEventListener {
private GLCanvas canvas;
private int imageWidth;
private int imageHeight;
private Nifty nifty;
private JoglInputSystem inputSystem;
private RenderDevice renderDevice;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Test2 test2 = new Test2();
Frame frame = new Frame("Test2");
frame.add(test2.canvas);
frame.setSize(test2.canvas.getWidth(), test2.canvas.getHeight());
final FPSAnimator fPSAnimator = new FPSAnimator(test2.canvas, 30);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
fPSAnimator.stop();
System.exit(0);
}
});
fPSAnimator.start();
frame.setVisible(true);
}
public Test2() {
initGL();
}
private void initGL() {
imageWidth = 800;
imageHeight = 600;
GLProfile profile = GLProfile.get(GLProfile.GL3);
GLCapabilities capabilities = new GLCapabilities(profile);
canvas = new GLCanvas(capabilities);
canvas.setSize(imageWidth, imageHeight);
canvas.addGLEventListener(this);
}
@Override
public void init(GLAutoDrawable drawable) {
renderDevice = new BatchRenderDevice(new JoglBatchRenderBackendCoreProfile(), 2048, 2048);
inputSystem = new JoglInputSystem();
// canvas.addMouseListener(inputSystem);
nifty = new Nifty(renderDevice, new NullSoundDevice(), inputSystem, new TimeProvider() {
@Override
public long getMsTime() {
return System.currentTimeMillis();
}
});
nifty.fromXmlWithoutStartScreen("test/helloworld.xml");
canvas.setAutoSwapBufferMode(true);
}
@Override
public void dispose(GLAutoDrawable drawable) {
}
@Override
public void display(GLAutoDrawable drawable) {
System.out.println("display");
GL3 gl3 = drawable.getGL().getGL3();
gl3.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl3.glClearDepthf(1.0f);
gl3.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
nifty.render(true);
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL3 gl3 = drawable.getGL().getGL3();
gl3.glViewport(x, y, width, height);
}
}Caused by: java.lang.NoClassDefFoundError: org/jglfont/spi/BitmapFontRenderer
at test.Test2.init(Test2.java:90)
Am I doing it right? If yes, where can I find the missing jar?
I am trying to figure it out from this hello world example
http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Hello_World_ExampleIn addition in the "examples for JOGL", he does something like
window.addMouseListener(inputSystem);
window.addKeyListener(inputSystem);Where
window = GLWindow.create(new GLCapabilities(getProfile(mode)));But if I try to do
canvas.addMouseListener(inputSystem);It returns error..