Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:19:23+00:00 2026-06-05T12:19:23+00:00

I’m currently experimenting with JOGL, and I ran into a problem which is really

  • 0

I’m currently experimenting with JOGL, and I ran into a problem which is really new to me. After starting the program, I see a blank window. After resize, I can normally see the content of it or if I do a minimise/restore. I suppose there is something with the events. The init() isn’t called after the window created, but after the first trigger with resize or minimise.

Here is the code what I’m using for creating a window and setting up OpenGL:

package com.cogwheel.framework.graphics;

import java.awt.BorderLayout;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.*;
import javax.swing.JFrame;

import com.cogwheel.framework.init.CWGPreferences;
import com.cogwheel.framework.util.CWGDebug;
import com.jogamp.opengl.util.Animator;

public class CWGOpenGLScreen extends JFrame implements GLEventListener {
private static final String TAG = "CWGOpenGLScreen";

private GLCanvas mCanvas;
private long fpsLast = System.currentTimeMillis();

public CWGOpenGLScreen(){
    this.setTitle(CWGPreferences.WINDOW_NAME);
    this.setSize(CWGPreferences.WINDOW_SIZE);
    this.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ///this.setResizable(false);
    this.setVisible(true);

    CWGDebug.info(TAG, "Window created!");

    CWGSetupGL();
}
private void CWGSetupGL(){
    GLCapabilities mCaps = new GLCapabilities(null);
    mCaps.setHardwareAccelerated(true);
    mCaps.setDoubleBuffered(true);

    mCanvas = new GLCanvas(mCaps);
    mCanvas.addGLEventListener(this);

    this.add(mCanvas, BorderLayout.CENTER);

    Animator animator = new Animator(mCanvas);
    animator.start();
}

public void CWGDrawScene(GLAutoDrawable drawable)
{
    CWGCalculateFPS();

    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glLoadIdentity();


    gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3f(1.0f, 0.0f, 0.0f);
        gl.glVertex3f(1.0f / 5 , 0.0f, 0.0f);

        gl.glColor3f(0.0f, 1.0f, 0.0f);
        gl.glVertex3f(1.0f / 5, 1.0f / 5, 0.0f);

        gl.glColor3f(0.0f, 0.0f, 1.0f);
        gl.glVertex3f(0.0f, 1.0f / 5, 1.0f / 5);
    gl.glEnd();
    gl.glFlush();
}

public void CWGCalculateFPS(){
    this.setTitle(CWGPreferences.WINDOW_NAME + " [" + 1000 / (System.currentTimeMillis() - fpsLast) + "]");
    fpsLast = System.currentTimeMillis();
}

public void init(GLAutoDrawable drawable){
        /*GL2 gl = drawable.getGL().getGL2();

        gl.glClearColor(0, 0, 0, 0);
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(0, 1, 0, 1, -1, 1);
        */
        CWGDebug.info(TAG, "Init called!");
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
public void display(GLAutoDrawable drawable){ CWGDrawScene(drawable); }
public void dispose(GLAutoDrawable drawable){}

}

Code quality is poor, I know, had no time to cleanup yet. Sorry for it.

Edit: got the problem, JFrame should not be shown until the GLEventListener is not initialised.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:19:24+00:00Added an answer on June 5, 2026 at 12:19 pm

    I’ve found your error (it has nothng to do with eclipse) : you should have set up the viewport (call to glViewport) whenever the canvas is resized => so you call glViewport(x,y, widht, height) in the reshape() method of the GLEventListener. So that OpenGL always knows where to draw scene, and not just when resizing frame.

    Also, don’t forget to setup screen (call to CWGSetupGL()) before showing it (otherwise you will still have the same problem, but only for a little time).

    Here the modified code (I’ve removed calls to CWGDebug.info as you did not provide this class, but you can put them back) :

    package com.cogwheel.framework.graphics;
    
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.media.opengl.GL;
    import javax.media.opengl.GL2;
    import javax.media.opengl.GLAutoDrawable;
    import javax.media.opengl.GLCapabilities;
    import javax.media.opengl.GLEventListener;
    import javax.media.opengl.awt.GLCanvas;
    import javax.swing.JFrame;
    
    import com.jogamp.opengl.util.Animator;
    
    public class CWGOpenGLScreen extends JFrame implements GLEventListener {
    
        public static void main(String[] args) {
            new CWGOpenGLScreen().setVisible(true);
        }
    
    private static final long serialVersionUID = 635066680731362587L;
    
    private static final String TAG = "CWGOpenGLScreen";
    
    private GLCanvas mCanvas;
    private long fpsLast = System.currentTimeMillis();
    
    public CWGOpenGLScreen(){
        this.setTitle(TAG);
        this.setSize(640,480);
        this.setLayout(new BorderLayout());
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ///this.setResizable(false);
    
        CWGSetupGL();
        this.setVisible(true);
    
    //    CWGDebug.info(TAG, "Window created!");
    }
    private void CWGSetupGL(){
        GLCapabilities mCaps = new GLCapabilities(null);
        mCaps.setHardwareAccelerated(true);
        mCaps.setDoubleBuffered(true);
    
        mCanvas = new GLCanvas(mCaps);
        mCanvas.addGLEventListener(this);
    
        this.add(mCanvas, BorderLayout.CENTER);
    
        final Animator animator = new Animator(mCanvas);
        animator.start();
    
        addWindowListener(new WindowAdapter() {
    
            @Override
            public void windowClosing(WindowEvent e) {
                animator.stop();
                System.exit(0);
            }
    
    
    
        });
    }
    
    public void CWGDrawScene(GLAutoDrawable drawable)
    {
        CWGCalculateFPS();
    
        GL2 gl = drawable.getGL().getGL2();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glLoadIdentity();
    
    
        gl.glBegin(GL.GL_TRIANGLES);
            gl.glColor3f(1.0f, 0.0f, 0.0f);
            gl.glVertex3f(1.0f / 5 , 0.0f, 0.0f);
    
            gl.glColor3f(0.0f, 1.0f, 0.0f);
            gl.glVertex3f(1.0f / 5, 1.0f / 5, 0.0f);
    
            gl.glColor3f(0.0f, 0.0f, 1.0f);
            gl.glVertex3f(0.0f, 1.0f / 5, 1.0f / 5);
        gl.glEnd();
        gl.glFlush();
    }
    
    public void CWGCalculateFPS(){
        this.setTitle(TAG + " [" + 1000 / (System.currentTimeMillis() - fpsLast) + "]");
        fpsLast = System.currentTimeMillis();
    }
    
    public void init(GLAutoDrawable drawable){
            /*GL2 gl = drawable.getGL().getGL2();
    
            gl.glClearColor(0, 0, 0, 0);
            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glLoadIdentity();
            gl.glOrtho(0, 1, 0, 1, -1, 1);
            */
    //        CWGDebug.info(TAG, "Init called!");
    }
    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){
        GL2 gl = drawable.getGL().getGL2();
        gl.glViewport(x, y, width, height);
    }
    //public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){}
    public void display(GLAutoDrawable drawable){ CWGDrawScene(drawable); }
    public void dispose(GLAutoDrawable drawable){}
    }
    

    Regards 🙂

    Edit : apologizes, I haven’t seen you replied yourself to your own question, by an edit.
    Anyway, I still think you’d better call glViewport in reshape() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.