Hi! well... lets go! :) Here is the code:
import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Dimension; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.awt.AWTGraphicsConfiguration; import javax.media.opengl.GL2; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLProfile; import javax.media.opengl.glu.GLU; import javax.swing.JFrame; import javax.swing.JPanel; public class ActiveRenderingCubeGL1 extends JFrame implements WindowListener { private CubeCanvasGL1 canvas; public ActiveRenderingCubeGL1(long period) { setLayout(new BorderLayout()); setResizable(false); add(makeRenderPanel(period), BorderLayout.CENTER); addWindowListener(this); pack(); setVisible(true); } private JPanel makeRenderPanel(long period) { JPanel renderPane = new JPanel(); renderPane.setLayout(new BorderLayout()); renderPane.setOpaque(false); GLProfile profile = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(profile); AWTGraphicsConfiguration config = AWTGraphicsConfiguration.create(this, caps, caps); NativeSurface surf = NativeWindowFactory.getNativeWindow(this, config); canvas = new CubeCanvasGL1(300, 300, period, config, caps, surf); canvas.setSize(new Dimension(300, 300)); canvas.setFocusable(true); canvas.requestFocus(); // canvas has focus, so receives key events renderPane.setSize(canvas.getPreferredSize()); renderPane.add(canvas, BorderLayout.CENTER); return renderPane; } public static void main(String[] args) { int fps = 60; long period = (long) 1000.0 / fps; new ActiveRenderingCubeGL(period * 1000000L); // ms --> nanosecs } } class CubeCanvasGL1 extends Canvas implements Runnable { private volatile boolean isRunning = false; private Thread animator; private GLDrawable drawable; // the rendering 'surface' private GLContext context; // the rendering context (holds rendering state // info) private GL2 gl; private GLU glu; private int cubeDList; private int panelWidth, panelHeight; private long period; public CubeCanvasGL1(int pwidth, int pheight, long period, AWTGraphicsConfiguration config, GLCapabilities caps, NativeSurface surf) { panelWidth = pwidth; panelHeight = pheight; this.period = period; drawable = GLDrawableFactory.getFactory(caps.getGLProfile()).createGLDrawable(surf); context = drawable.createContext(null); } @Override public void run() { initRender(); renderLoop(); context.destroy(); System.exit(0); } private void initRender() { // TODO Auto-generated method stub } private void renderLoop() { while (isRunning) { makeContentCurrent(); renderScene(); // rendering } } private void renderScene() { // TODO Auto-generated method stub } private void makeContentCurrent() { try { while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) { System.out.println("Context not yet current..."); Thread.sleep(100); } } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void addNotify() { // TODO Auto-generated method stub super.addNotify(); drawable.setRealized(true); // canvas can now be used for rendering // initialize and start the animation thread if (animator == null || !isRunning) { animator = new Thread(this); animator.start(); } } }here is the stack trace:
|
Administrator
|
Seems to me u really got a quite complicated 'low-level'-ish setup (don't know if ur approach is even feasable). Why not simply use javax.media.opengl.awt.GLCanvas in conjunction with com.jogamp.opengl.util.Animator to get a basic JOGL application up and running ?
... and btw: Have u already taken a look at the starter tutorials from Justin and Wade ? http://jogamp.org/wiki/index.php/Jogl_Tutorial |
Administrator
|
In reply to this post by dim_9999
Have you tried the latest autobuild? I found a bug https://jogamp.org/bugzilla/show_bug.cgi?id=468 a couple of days ago that gave the same error, and got a patch merged in yesterday.
|
In reply to this post by Demoscene Passivist
thanks for answer. and yes, i have already seen wiki's tutorials... well, i just trying to make some stuff from a book, that calling "Apress.Pro.Java.6.3D.Game.Development.Java.3D.JOGL.JInput.and.JOAL.APIs.Apr.2007"... At that book this stuff is calling "active rendering" and it is jogl-1.1 related... here is the link ok, if nothing good will happened i'll try more simple ways...
|
Free forum by Nabble | Edit this page |