A problem with a tutorial

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

A problem with a tutorial

Dan
Hello, I've recently been following the great tutorial at http://sites.google.com/site/justinscsstuff/jogl-tutorial-3 .

Although I've stumbled upon a problem when I try to render a static triangle in the window. Instead of getting a triangle as one would expect, I get a blank window.

The source code I'm trying is as follows:

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;

public class SimpleScene implements GLEventListener {
    public static void main(String[] args) {
GLProfile.initSingleton();
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

        Frame frame = new Frame("AWT Window Test");
        frame.setSize(300, 300);
        frame.add(canvas);
        frame.setVisible(true);
       
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
       
        canvas.addGLEventListener(new SimpleScene());
    }

        @Override
        public void display(GLAutoDrawable drawable) {
                update();
            render(drawable);
        }
       
        private void update() {
        }
       
        private void render(GLAutoDrawable drawable) {
            GL2 gl = drawable.getGL().getGL2();
           
            gl.glBegin(GL.GL_TRIANGLES);
            gl.glColor3f(1, 0, 0);
            gl.glVertex2f(-1, -1);
            gl.glColor3f(0, 1, 0);
            gl.glVertex2f(0, 1);
            gl.glColor3f(0, 0, 1);
            gl.glVertex2f(1, -1);
            gl.glEnd();
        }

        @Override
        public void dispose(GLAutoDrawable arg0) {
        }

        @Override
        public void init(GLAutoDrawable arg0) {
        }

        @Override
        public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
                        int arg4) {
        }
}


To make sure it wasn't me setting up JOGL badly, I also checked to the next part of the tutorial (with the animated triangle), for some reason this seems to work perfectly.

I've read around that you need an animation in the program to get it working, although I could be confused with something very different.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Wade Walker
Administrator
I get the same result as you when I run this tutorial. The window is blank unless I put these lines at the bottom of the main method:

        FPSAnimator animator = new FPSAnimator(canvas, 60);
        animator.add(canvas);
        animator.start();

Without these lines, the render() method is never called, because the canvas doesn't recieve any events that it can pass on to the SimpleScene.

You can also do canvas.display() at the end of your main method, but that only shows you the triangle for a moment -- it seems to be auto-flipping. I'm not sure why it acts different on Justin's machine -- maybe he'll see this and comment. I usually use SWT instead of AWT so I'm not an expert in this area.
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Justin
In reply to this post by Dan
Hi,

Strange. I'll have to update the tutorial if this is true. I did test this on a couple different machines with different operating systems (Mac, Windows, Linux) and GPUs. Maybe something has changed in the JOGL releases; I'm not really sure.

Why did it work for me? The reshape method should trigger a call to the display method last time I checked. At least on my machine, reshape is actually called while the window / frame and its decorations are set up (without user interaction). If you resize the window that pops up, does it show a triangle then?

To show this, put a System.out.println("reshape called"); inside the reshape method, and another similar print statement in the display method. You should see something like this:

Reshape called
Display called

or maybe even

Reshape called
Display called
Display called

Justin
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

gouessej
Administrator
In reply to this post by Wade Walker
Please don't use FPSAnimator, it doesn't have the same behavior on Linux and Windows. Use Animator.
Julien Gouesse | Personal blog | Website
Dan
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Dan
In reply to this post by Justin
It appears that render is never called, nor is reshape.

Although as soon as an animator is added, they are.
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Wade Walker
Administrator
I also tried this on Linux (CentOS 5.4 x86_64) and got the same results, with an extra twist -- you can't shut the app down by clicking the close box or clicking "stop" in Eclipse. I have to "kill -KILL" it from the command line.

When I comment out all the JOGL stuff and just leave the AWT frame, it works fine. But commenting in even the single command "GLProfile.initSingleton()" brings back the bad behavior.

I also checked the ability to add a mouse listener to the frame -- if JOGL is commented in, it receives no messages, but with JOGL commented out it works fine.

I'll work up a bug report on this later; I need to try a few more things to be sure what's going on.
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

gouessej
Administrator
Build JOGL by yourself and it works without killing the process....
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Wade Walker
Administrator
gouessej wrote
Build JOGL by yourself and it works without killing the process....
I can't ask the casual user who's just trying out a tutorial to build JOGL himself -- I think it's too much for the non-expert

I tried Justin's tutorial with the version of JOGL he used (b162 instead of b187) and I see the same problem, so it's not a recent regression.

The bug of not being able to quit on Linux using AWT looks like http://jogamp.org/bugzilla/show_bug.cgi?id=401. I'll put more information on that bug to help reproduce it.

In summary: There seems to be some difficulty with native window events and AWT in the current JOGL that prevents the single-triangle demo from showing up properly on some platforms.
Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Wade Walker
Administrator
In reply to this post by Dan
Dan wrote
It appears that render is never called, nor is reshape.
This bug is now fixed. It was bug 401, you can see it at http://jogamp.org/bugzilla/show_bug.cgi?id=401. If you download the latest autobuild and try again, you'll see that reshape is called correctly now. I've confirmed that it works with b211 (http://jogamp.org/deployment/autobuilds/jogl-b211-2010-11-10_03-31-02/) on Windows 7 64-bit.

Reply | Threaded
Open this post in threaded view
|

Re: A problem with a tutorial

Sven Gothel
Administrator
On Friday, November 12, 2010 15:10:12 Wade Walker [via jogamp] wrote:

>
> Dan wrote:
> >
> > It appears that render is never called, nor is reshape.
> >
>
> This bug is now fixed. It was bug 401, you can see it at
> http://jogamp.org/bugzilla/show_bug.cgi?id=401. If you download the latest
> autobuild and try again, you'll see that reshape is called correctly now.
> I've confirmed that it works with b211
> (http://jogamp.org/deployment/autobuilds/jogl-b211-2010-11-10_03-31-02/) on
> Windows 7 64-bit.

Awesome, thank you Wade.

~Sven