jogl problem1

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

jogl problem1

dim_9999
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:
  1. Exception in thread "main" java.lang.ClassCastException: javax.media.nativewindow.awt.AWTGraphicsConfiguration cannot be cast to com.jogamp.opengl.impl.windows.wgl.WindowsWGLGraphicsConfiguration
  2.     at com.jogamp.opengl.impl.windows.wgl.WindowsWGLDrawable.setRealizedImpl(WindowsWGLDrawable.java:70)
  3.     at com.jogamp.opengl.impl.GLDrawableImpl.setRealized(GLDrawableImpl.java:155)
  4.     at book.CubeCanvasGL.addNotify(ActiveRenderingCubeGL.java:325)
  5.     at java.awt.Container.addNotify(Container.java:2578)
  6.     at javax.swing.JComponent.addNotify(JComponent.java:4685)
  7.     at java.awt.Container.addNotify(Container.java:2578)
  8.     at javax.swing.JComponent.addNotify(JComponent.java:4685)
  9.     at java.awt.Container.addNotify(Container.java:2578)
  10.     at javax.swing.JComponent.addNotify(JComponent.java:4685)
  11.     at java.awt.Container.addNotify(Container.java:2578)
  12.     at javax.swing.JComponent.addNotify(JComponent.java:4685)
  13.     at javax.swing.JRootPane.addNotify(JRootPane.java:739)
  14.     at java.awt.Container.addNotify(Container.java:2578)
  15.     at java.awt.Window.addNotify(Window.java:663)
  16.     at java.awt.Frame.addNotify(Frame.java:470)
  17.     at java.awt.Window.pack(Window.java:704)
  18.     at book.ActiveRenderingCubeGL.<init>(ActiveRenderingCubeGL.java:33)
  19.     at book.ActiveRenderingCubeGL1.main(ActiveRenderingCubeGL1.java:60)
  20.  
I can't realize how to make that cast correctly or something else...? any suggestions? thanks.
Reply | Threaded
Open this post in threaded view
|

Re: jogl problem1

Demoscene Passivist
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
Reply | Threaded
Open this post in threaded view
|

Re: jogl problem1

Wade Walker
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.
Reply | Threaded
Open this post in threaded view
|

Re: jogl problem1

dim_9999
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...
Reply | Threaded
Open this post in threaded view
|

Re: jogl problem1

dim_9999
In reply to this post by Wade Walker
actually, i have forgot to say that i am working under win7 amd64.

i have already tried, and the result is the same...