Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.
codeanticode edited this page Apr 3, 2019 · 7 revisions

This LWJGL-based OPENGL renderer is an alternative to the default OpenGL renderer in Processing, based on the LWJGL 3 bindings. The default OpenGL renderer is uses the JOGL bindings.

Getting started

In order to get started with this LWJGL renderer, you need to clone the processing repo in addition to this repo, for example:

mkdir devel
cd devel
git clone git@github.com:processing/processing.git
git clone git@github.com:codeanticode/processing-lwjgl.git

You can follow the build instructions listed in the Processing wiki to build Processing. Once you have done that, you can add both github repos into Eclipse, and choose the projects to import. The Processing repo contains many projects but you only need processing-core in order to test the LWJGL renderer from Eclipse. The processing-lwjgl contains two projects, the rendering library itself, and LWJGL-Test with two test samples. Once all of these project are imported into Eclipse (with Processing properly built) you should get something like this:

image

The libraries in the Build Path of processing-lwjgl project assume you are on Mac:

image

so you would need to change them to the corresponding Windows/Linux jars when on those platforms.

Test code

The LWJGL-test project contains two simple test samples, one that is a basic "Hello LWJGL" application that just shows an OpenGL window and prints the mouse events in the console (it does not depend on Processing at all), and a PSketch application that uses Processing to render a 3D cube. When running these examples on Mac, you need to add the -XstartOnFirstThread argument to VM arguments under Run Configurations for each application:

image

Challenges

GLFW-AWT incompatibility on Mac

The new renderer appears to work well on Windows, however, there are some challenges to overcome on Mac. First of all, LWJGL3 uses the cross-platform toolkit GLFW to manage windows and events. GLFW requires the VM command -XstartOnFirstThread on Mac in order to function, but that command breaks AWT, as discussed in several places, like here and here.

You can see the effects of combining -XstartOnFirstThread with AWT (even just initializing AWT and doing nothing else with it) by uncommenting some of the commented lines in the initialization the HelloLWGL example.

Making AWT optional in PApplet

A solution to the above problem could be modularizing away these specific AWT-related calls in the base PApplet class in Processing, and performing them only when using the default renderers as a possible way of making Processing compatible with LWJGL and GLFW on Mac. But this would require making changes to how sketch initialization works in the core of Processing. That being said, there are only few places where Processing uses AWT, such as file selection with selectInput() that would need to move to Surface, and probably adding a few more methods to handle the init stuff that’s in PApplet.main().

A complete list of AWT imports in PApplet (and their role) is provided below:

  • dummy object for backwards compatibility, plus the select methods

    • import java.awt.Frame;
  • before calling settings() to get displayWidth/Height

    • import java.awt.DisplayMode;
  • handleSettings() and displayDensity()

    • import java.awt.GraphicsDevice;
    • import java.awt.GraphicsEnvironment;
  • used to present the fullScreen() warning about Spaces on OS X

    • import javax.swing.JOptionPane;
  • inside runSketch() to warn users about headless

    • import java.awt.HeadlessException;
    • import java.awt.Toolkit;
  • used by loadImage()

    • import java.awt.Image;
    • import java.awt.color.ColorSpace;
    • import java.awt.image.BufferedImage;
    • import javax.imageio.ImageIO;
  • allows us to remove Processing's MediaTracker code

    • import javax.swing.ImageIcon;
  • used by selectInput(), selectOutput(), selectFolder()

    • import java.awt.EventQueue;
    • import java.awt.FileDialog;
    • import javax.swing.JFileChooser;
  • set the look and feel, if specified

    • import javax.swing.UIManager;
  • used by link()

    • import java.awt.Desktop;
  • used by desktopFile() method

    • import javax.swing.filechooser.FileSystemView;
Clone this wiki locally