Login  Register

Re: Drawing problem when height > width

Posted by Djak on Jan 28, 2011; 9:33am
URL: https://forum.jogamp.org/Drawing-problem-when-height-width-tp2361172p2366084.html

Thank you very much for your help :)
I tested your test case and it works very fine, so I modified it to adapted from my application and I got the same problem but I don't understand it well. I must make a mistake in the projection matrix configuration but I don't understand why it's linked to the dimensions of the frame. Here is the new code :

import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;

public class OneTriangle {
    protected static void setup( GL gl, int width, int height ) {
        gl.glViewport( 0, 0, width, height );
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU glu = new GLU();
        glu.gluPerspective(45, width / height, 1, 50000);
               
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
               
    }

    protected static void render( GL gl, int width, int height ) {
        gl.glClear( GL.GL_COLOR_BUFFER_BIT );
// new triangle
     gl.glLoadIdentity();
        gl.glBegin( GL.GL_TRIANGLES );
        gl.glColor3f( 1, 0, 0 );
        gl.glVertex2f( 0, 1 );
        gl.glColor3f( 0, 1, 0 );
        gl.glVertex2f( -1, 0 );
        gl.glColor3f( 0, 0, 1 );
        gl.glVertex2f( 1, 0);
        gl.glEnd();
    }
}
************************
and added an animator :
*************************

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;

import com.sun.opengl.util.FPSAnimator;

public class OneTriangleAWT {

    public static void main(String [] args) {
        final Frame frame = new Frame( "One Triangle AWT" );
        GLCapabilities glcapabilities = new GLCapabilities();
        final GLCanvas glcanvas = new GLCanvas( glcapabilities );
        glcanvas.addGLEventListener( new GLEventListener() {
           
            @Override
            public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
                OneTriangle.setup( glautodrawable.getGL(), width, height );
            }
           
            @Override
            public void init( GLAutoDrawable glautodrawable ) {
            }
           
            @Override
            public void display( GLAutoDrawable glautodrawable ) {
                OneTriangle.render( glautodrawable.getGL(), glautodrawable.getWidth(), glautodrawable.getHeight() );
            }

            @Override
            public void displayChanged( GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged ) {
            }
        });

    // Animator
                final FPSAnimator animator = new FPSAnimator(glcanvas, 60);
                animator.start();
       
        frame.add( glcanvas );
        frame.addWindowListener( new WindowAdapter() {
            public void windowClosing( WindowEvent windowevent ) {
                frame.remove( glcanvas );
                frame.dispose();
                System.exit( 0 );
            }
        });

        frame.setSize( 640, 480 );
        frame.setVisible( true );
    }
}


Now, the triangle is drawn but only if height > width. And I made a mistake in my problem description, scene is drawn, but some objects are not drawn (in my other application, background color is grey, so I can see scene is drawn but I can't see objects of the scene). Anyone see something bad in this matrix configuration ?
Thanks in advance

@gouessej : I'll switch to 2.0 a few later. Actually, I got some BSOD from ATI drivers from some pre-releases of 2.0 and needed to rollback to 1.1.1. I'll retry 2.0 with same drivers as soon as possible.