sigh It doesn’t matter how small the program is, this always happens. I thought that it could be jogl, because I think it uses the awt eventqueue, but even when I copy and paste the tut programs off the internet this still happens.
Anyway since you guys want an MCVE here you go
package FFS02_Leveled;
public class LevelEdMain
{
static Thread thread;
static LevelEd leveled;
public static void main(String[] args)
{
leveled = new LevelEd();
thread = new Thread(leveled, "Main-Level Editor Thread");
thread.start();
}
}
package FFS02_Leveled;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.filechooser.FileNameExtensionFilter;
public class LevelEd extends JFrame implements GLEventListener, KeyListener, MouseListener, MouseMotionListener, Runnable
{
private static final long serialVersionUID = 3669760361816887841L;
//STANDARD VARIABLES
private long g_last_time;
private GL2 g_gl;
private GLU g_glu;
protected GLCanvas g_glcanvas;
public LevelEd()
{
super("FFS02Leveled");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();//Get monitor dimensions
float scale = 1.0f;//Set the scaling of the window
//Set the window width and height
int window_width = (int) (dimension.width * scale);
int window_height = (int) (dimension.height * scale) - 48;
init(window_width, window_height);//Initialize our variables
startOpenGL();
}
public synchronized void display(GLAutoDrawable gld)
{
GL2 g_gl = gld.getGL().getGL2();
}
public void dispose(GLAutoDrawable arg0)
{
}
public void init(GLAutoDrawable gld)
{
//Make a new glu, glut, and gl for using OpenGL
g_gl = gld.getGL().getGL2();
g_glu = new GLU();
g_gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);//Set the default background color
g_gl.glEnable(GL.GL_DEPTH_TEST);
g_gl.glEnable(GL.GL_CULL_FACE);
g_gl.glDepthFunc(GL.GL_LEQUAL);
int sample_buffers[] = new int[1];
int samples_for_buffer[] = new int[1];
g_gl.glGetIntegerv(GL.GL_SAMPLE_BUFFERS, sample_buffers, 0);
g_gl.glGetIntegerv(GL.GL_SAMPLES, samples_for_buffer, 0);
g_gl.glEnable(GL.GL_MULTISAMPLE);
g_gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
g_gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
public void init(int window_width, int window_height)
{
int w = 80;
int h = 24;
JMenuBar menu_bar = new JMenuBar();
setJMenuBar(menu_bar);
JMenu menu_file = new JMenu("File");
menu_file.setPreferredSize(new Dimension(50, h));
menu_bar.add(menu_file);
JMenuItem file_load = new JMenuItem("Load");
file_load.setPreferredSize(new Dimension(w, h));
file_load.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser("./resources/levels");
fc.setDialogTitle("Open .lvl File");
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Level File", "lvl");
fc.setFileFilter(filter);
int return_val = fc.showOpenDialog(null);
if(return_val == JFileChooser.APPROVE_OPTION)
{
}
}
});
menu_file.add(file_load);
}
public synchronized void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
public void mouseClicked(MouseEvent arg0)
{
}
public void mouseDragged(MouseEvent arg0)
{
}
public void mouseEntered(MouseEvent arg0)
{
}
public void mouseExited(MouseEvent arg0)
{
}
public void mouseMoved(MouseEvent arg0)
{
}
public void mousePressed(MouseEvent arg0)
{
}
public void mouseReleased(MouseEvent arg0)
{
}
public void reshape(GLAutoDrawable gld, int x, int y, int width, int height)
{
}
public void run()
{
boolean running = true;
g_last_time = System.nanoTime();
final double ns = 1_000_000_000.0 / 60.0;//Limits to 60 updates per second
double delta = 0;
double delta_time = 0;
double limiter = 0.15;
double previous_time = 1.0;
double current_time = System.nanoTime() * 0.000000001;
while(running)
{
long new_time = System.nanoTime();
delta += (new_time - g_last_time) / ns;
g_last_time = new_time;
current_time = System.nanoTime() * 0.000000001;//Convert to Seconds
delta_time = delta_time > limiter ? limiter : current_time - previous_time;
previous_time = current_time;
while(delta >= 1)
{
update(delta_time);
delta--;
}
g_glcanvas.display();
}
}
private void startOpenGL()
{
g_glcanvas.addGLEventListener(this);
g_glcanvas.addKeyListener(this);
g_glcanvas.addMouseListener(this);
g_glcanvas.addMouseMotionListener(this);
}
public synchronized void update(double delta_time)
{
}
}