Login  Register

Problem running OpenGL application in Eclipse using JOGL

Posted by Strider on Mar 26, 2024; 1:48am
URL: https://forum.jogamp.org/Problem-running-OpenGL-application-in-Eclipse-using-JOGL-tp4043439.html

I am having difficulty running an OpenGL application in Eclipse using JOGL (Java OpenGL). I have carefully followed the setup instructions and verified that my code is correctly implemented. However, when running the application, the window appears blank and only briefly shows the rendered content before disappearing.

I've checked my configuration in Eclipse and it appears to be set correctly. Additionally, I have tested the same application on my college lab computers and it works fine, which makes me think the problem could be related to my personal configuration or hardware.

My computer has an AMD Ryzen 5 3400G processor.

I am attaching the code I am using below:

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 Principal extends JFrame implements GLEventListener{
        private static final long serialVersionUID = 1L;

        public static void main(String[] args) {
        // TODO Auto-generated method stub
        Principal ren= new Principal();
        }
        public Principal() {
                super("Programación Gráfica - OpenGL");
                this.setSize(640,480);
                this.setLocationRelativeTo(null);
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.setResizable(false);
               
                GLProfile profile = GLProfile.get(GLProfile.GL2);
                GLCapabilities caps = new GLCapabilities(profile);
                GLCanvas canvas = new GLCanvas(caps);
                canvas.addGLEventListener(this);
                this.add(canvas);
                this.setVisible(true);
                canvas.requestFocusInWindow();
        }

        @Override
        public void display(GLAutoDrawable drawable) {
                // TODO Auto-generated method stub
                GL2 gl = drawable.getGL().getGL2();
                gl.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
                gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
                gl.glFlush();
        }

        @Override
        public void dispose(GLAutoDrawable drawable) {
                // TODO Auto-generated method stub
        }

        @Override
        public void init(GLAutoDrawable drawable) {
                // TODO Auto-generated method stub
                GL2 gl = drawable.getGL().getGL2();
                gl.glClearColor(0.392f, 0.584f, 0.929f, 1.0f);
        }

        @Override
        public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
                // TODO Auto-generated method stub
        }
       
}

I would greatly appreciate any help or suggestions on how to fix this issue. Are there any specific settings I should check on my computer with an AMD processor? Has anyone else experienced a similar problem when trying to run OpenGL applications on AMD hardware?

Thank you in advance for your help!