Login  Register

Re: drawable render issue

Posted by roeeNavon on Mar 10, 2024; 5:35pm
URL: https://forum.jogamp.org/drawable-render-issue-tp4043384p4043387.html

Hi

this is the SSCCE:
package main;

import javax.swing.JFrame;

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;

public class MVP implements GLEventListener {
        private static final int WIN_WIDTH = 600;
        private static final int WIN_HEIGHT = 400;

        public static void main(String[] args) {
                JFrame frame = new JFrame("JOGL Application");
                GLProfile profile = GLProfile.getDefault();
                GLCapabilities capabilities = new GLCapabilities(profile);
                GLCanvas canvas = new GLCanvas(capabilities);

                MVP mainInstance = new MVP();
                canvas.addGLEventListener(mainInstance);

                frame.getContentPane().add(canvas);
                frame.setSize(WIN_WIDTH, WIN_HEIGHT);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);

        }

        @Override
        public void init(GLAutoDrawable drawable) {
        }

        @Override
        public void display(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();

                gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT);

                gl.glMatrixMode(GL2.GL_PROJECTION);
                gl.glLoadIdentity();
                gl.glOrtho(0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0, -1, 1);

                gl.glMatrixMode(GL2.GL_MODELVIEW);
                gl.glLoadIdentity();

                gl.glBegin(GL2.GL_QUADS);
                gl.glColor3f(1.0f, 0.0f, 0.0f); // Set color to red
                gl.glVertex2f(0, 0); // Bottom-left corner
                gl.glVertex2f(32, 0); // Bottom-right corner
                gl.glVertex2f(32, 32); // Top-right corner
                gl.glVertex2f(0, 32); // Top-left corner
                gl.glEnd();
                gl.glFlush();
        }

        @Override
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
                // Unused
        }

        @Override
        public void dispose(GLAutoDrawable drawable) {
                // Unused
        }
}

About the versions:
- i am currently use maven, this is the dependcy:
        <groupId>org.jogamp.jogl</groupId>
        <artifactId>jogl-all</artifactId>
        <version>2.3.2</version>
- i was using a jar file before, which i cant find, but it was a way older version