Hello Guest

AWTGLCanvas multisampling with JFrame

  • 2 Replies
AWTGLCanvas multisampling with JFrame
« on: April 24, 2017, 13:08:42 »

I am trying to enable multisampling for a AWTGLCanvas that is places inside a Java Swing JFrame.

Until now I have no success to do so. I found an old thread that solved this within an Applet (http://forum.lwjgl.org/index.php?topic=1889.msg11119). But setting the PixelFormat as described in that post has no effect.

Do you please have any other tips to get the multisampling working?


Update: Added code sample.

Code: [Select]
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluOrtho2D;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.PixelFormat;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class CanvasTest {

  public static class CustomAWTGLCanvas extends AWTGLCanvas {

    public CustomAWTGLCanvas() throws LWJGLException {
      super(new PixelFormat(8, 8, 0, 4));

    public void paintGL() {
      try {
        glViewport(0, 0, getWidth(), getHeight());
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
        glColor3f(1f, 1f, 0f);
        glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
        glRotatef(51f, 0f, 0f, 1.0f);
        glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
      } catch (LWJGLException ex) {

  public static void main(String[] args) throws LWJGLException {

    CustomAWTGLCanvas canvas = new CustomAWTGLCanvas();

    JPanel panel = new JPanel(new BorderLayout());
    panel.setMinimumSize(new Dimension(100, 100));

    JFrame frame = new JFrame("AWTGLCanvas - multisampling");
    frame.setPreferredSize(new Dimension(640, 480));

« Last Edit: April 26, 2017, 07:26:39 by dzolo »



Re: AWTGLCanvas multisampling with JFrame
« Reply #1 on: May 07, 2017, 17:01:55 »
Please note that LWJGL 2 is not maintained anymore for well over two years now.
You are very encouraged to upgrade to the current version 3, if you can. GLFW supports multiple windows. So if this was your reason to choose AWT, you don't need that anymore.
See: https://www.lwjgl.org/download
And I also cannot reproduce any bug with lacking multisampling on Windows 7 x64 with the LWJGL 2.9.3 release.

Taking your exact example code with sample count 8 produces:

Using sample count 0 produces:

You can clearly see the jagged edges in the last image.

A few questions:
- which OS are you using? (if some Linux variant, maybe with some custom compositor/window manager?)
- which exact version of LWJGL 2 are you using?
« Last Edit: May 07, 2017, 17:33:30 by Kai »

Re: AWTGLCanvas multisampling with JFrame
« Reply #2 on: May 15, 2017, 15:27:16 »
Hi Kai,

unfortunately I am using libgdx which do not provide LWJGL3 AWT backend yet.

You are right it works. Previously I was testing it on Ubuntu 16.04 with Unity7 window manager when the example does not work.
When I tried the example in Windows 7 it has worked as expected.

Thank You for your suggestion!