Login  Register

Re: JOGL 2 rc11 newt + Windows 8

Posted by juankprada on Feb 19, 2013; 3:03pm
URL: https://forum.jogamp.org/JOGL-2-rc11-newt-Windows-8-tp4028259p4028282.html

Hi gouessej

Yes, I use an AWT Frame and I added an NewtCanvasAWT which contains the GLWindow. The code is the following:

public abstract class GameWindow implements GLEventListener {

	protected static int windowHeight;
	protected static int windowWidth;

	public static int getWindowHeight() {
		return windowHeight;
	}
	
	public static int getWindowWidth() {
		return windowWidth;
	}
	
	protected GLWindow canvas;

	private KeyListener currentKeyListener;
	
	private MouseListener currentMouseListener;
	
	/** The recorded fps */
	protected int fps;

	private Frame frame;

	protected GL gl;

	protected List<ByteBuffer> icons = new ArrayList<ByteBuffer>();
	
	final int TARGET_FPS = 60;
	
	final long OPTIMAL_TIME = 1000 / TARGET_FPS;

	protected boolean running;

	protected String windowTitle;
	
	protected AnimatorBase animator;

	public GameWindow() {
		this.running = true;
		
	}

	public GameWindow(int windowWidth, int windowHeight, String windowTitle) {
		this();

		windowWidth = windowWidth;
		windowHeight = windowHeight;
		this.windowTitle = windowTitle;

		createDisplay();
	}

	public void createDisplay() {

		GLProfile glp = GLProfile.getGL2GL3();
		GLCapabilities caps = new GLCapabilities(glp);
		canvas = GLWindow.create(caps);
		
		frame = new Frame(windowTitle);
		
		frame.setSize(windowWidth, windowHeight);
		frame.setResizable(false);
		

		// Get the screen size
		GraphicsConfiguration gc = frame.getGraphicsConfiguration();
		Rectangle bounds = gc.getBounds();
		
		canvas.addWindowListener(new WindowAdapter() {
			public void windowDestroyNotify(WindowEvent e) {
				System.exit(0);
			}
		});

		canvas.addGLEventListener(this);
		canvas.setSize(windowWidth, windowHeight);
		
		
		final NewtCanvasAWT canvasAWT = new NewtCanvasAWT(canvas);
		canvasAWT.setSize(windowWidth, windowHeight);
		
		frame.add(canvasAWT);
		frame.setUndecorated(false);
		frame.pack();
		Dimension size = frame.getPreferredSize();
		frame.setLocation((int) ((bounds.width / 2) - (size.getWidth() / 2)),
				(int) ((bounds.height / 2) - (size.getHeight() / 2)));

		Image icon = Toolkit.getDefaultToolkit().getImage(
				ResourceLoader.loadResource("icons/icon32x32.png"));
		frame.setIconImage(icon);
		frame.setVisible(true);

		animator = new FPSAnimator(canvas, TARGET_FPS);
		
		animator.setUpdateFPSFrames(TARGET_FPS, null);

		animator.start();
	}

	@Override
	public void display(GLAutoDrawable drawable) {

		this.gl = canvas.getGL();
		this.gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		

		onUpdate();
		
		if(animator != null)
			this.frame.setTitle(windowTitle + " (FPS: " + animator.getTotalFPS()+ ")");
		
		onRender();
		
		
	}

	@Override
	public void dispose(GLAutoDrawable drawable) {
		onClose();
	}

	@Override
	public void init(GLAutoDrawable drawable) {
		onInit(drawable);
	}

	public abstract void onClose();

	public abstract void onInit(GLAutoDrawable drawable);

	public abstract void onRender();

	public abstract void onStart();

	public abstract void onUpdate();

	public void replaceMouseListener(MouseListener mouseListener) {
		if(this.currentMouseListener != null) {
			this.canvas.removeMouseListener(this.currentMouseListener);
		}
		
		this.currentMouseListener = mouseListener;
		this.canvas.addMouseListener(this.currentMouseListener);
	}

	@Override
	public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
	}

}


That is what I use to create my OpenGL window. That class is used by another one that sets the window width and height and calls createDisplay(). Nothing fancy in my opinion.

About Windows 7 I really dont know as I dont have access to a Windows 7 machine.

Im just wondering if such an issue could be due to bad or outdated drivers?

Thank you for your response.

Regards