Skip to content

SecretSheppy/jogl-with-jetbrains-ides

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using JOGL (Java OpenGL) in JetBrains IDEs

A guide to using the JOGL (Java OpenGL) bindings with JetBrains IDEs. This guide uses IntelliJ IDEA Ultimate and JOGL 2.6.0, but the same steps will work in the Community edition. I may use Windows specific terms in this guide, for instance file paths that start with the C: drive, however all of these instructions will work on any operating system (just make sure to adapt these to fit your operating systems requirements).

Choices for using JOGL with JetBrains IDEs

There are 3 main ways to install and use the JOGL bindings in IntelliJ, these are:

Install as JAR Library

Download the jogamp-fat.jar file from jogamp.org. This file contains all the JOGL libraries and natives.

jogamp.org jogamp-fat.jar

Create a folder to store the JOGL library. I prefer to keep all of my JAR libraries in one place, so I created a C:/Users/MyUserName/Libs/jogl folder to store the jogamp-fat.jar file, but you can create this wherever you like. Once you've created this folder, move the jogamp-fat.jar file into it.

Now launch IntelliJ and either create a new project or open your existing JOGL project. Open File > Project Structure.

file project structure

Click the Modules tab from the menu in the newly opened window.

modules tab

Click the + button in the tab, then select Library then select Java.

plus library java

Navigate to the folder that jogamp-fat.jar is stored in and press Select Folder.

select folder

Press Okay to confirm the library creation.

confirm library

Make sure to check the library to enable it in your project, then hit apply.

select library and apply

Now JOGL is successfully installed into your project. Make sure to read the Installing JOGL Sources section before you get started with development.

Install with Maven (pom.xml) or Gradle

To install with Maven or Gradle using their build files, use the information from jogamp wiki.

Install with Maven (JetBrains)

Launch IntelliJ and either create a new project or open your existing JOGL project. Open File > Project Structure.

file project structure

Click the Modules tab from the menu in the newly opened window.

modules tab

Click the + button in the tab, then select Library then select From Maven....

mvn jetbrains

Type jogl-all into the input field, and select the desired version from the search results. Then press okay.

jogl all mvn jetbrains

Make sure to check the library to enable it in your project, then hit apply.

select library and apply mvn

Now JOGL is successfully installed into your project. Make sure to read the Installing JOGL Sources section before you get started with development.

Installing JOGL Sources

Installing the JOGL sources is something you will want to do, or you will be missing useful information like Javadoc on hover and function parameter names etc...

missing sources

Installing JOGL sources will fix this problem.

jogl loaded sources

To install the JOGL sources, follow the guide relevant to your JOGL install method:

JAR Library

On Maven Central, navigate to the version of JOGL that you are using.

mvn central jogl 2.6.0

In the files row of the table, click View All.

mvn central jogl 2.6.0 view all

Download the jogl-all-x.x.x-sources.jar file.

mvn central jogl 2.6.0 sources

Store the sources file wherever you would like.

Declare a JOGL variable (for example GL3 gl;) in the main function;

import com.jogamp.opengl.GL3;

public class Demo extends GLEventListener { // can ctrl + click on GLEventListener
    public static void main() {
        GL3 gl; // can ctrl + click on GL3
    }
}

Either Ctrl + Click on the type or press Alt + F4 whilst your cursor is within the type definition. This opens the decompiled bytecode, there will be a blue ribbon at the top of the file. Press Choose Sources....

jar choose sources

Navigate to your jogl-all-x.x.x-sources.jar file and select it.

jar load sources

You have now successfully loaded the JOGL sources.

Make sure to read the Running a Project section before developing your project.

Maven (any) and Gradle

Declare a JOGL variable (for example GL3 gl;) in the main function;

import com.jogamp.opengl.GL3;

public class Demo extends GLEventListener { // can ctrl + click on GLEventListener
    public static void main() {
        GL3 gl; // can ctrl + click on GL3
    }
}

Either Ctrl + Click on the type or press Alt + F4 whilst your cursor is within the type definition. This opens the decompiled bytecode, there will be a blue ribbon at the top of the file. Press Download....

jar choose sources

Maven or Gradle will then download and install the sources for you. If this fails, following the JAR tutorial will work.

Make sure to read the Running a Project section before developing your project.

Running a Project

The best way to run a JOGL project in Jetbrains is to use a Run Configuration. You can generate one automatically by clicking on the green triangle that appears in the gutter of the editor on the same line as your main function or class definition.

green triangle

This will create a default run configuration with your main classes name which will be accessible from the configurations menu in the top right of the IntelliJ interface.

default configuration

When you run this configuration, however, it will likely fail to work. This can be easily resolved by adding some vm arguments to the configuration. To do this, select Edit Configurations... from the configurations menu.

edit configurations

Select Modify options and then select Add VM options.

add vm arguments

This will add a new input field to the UI. Paste the following exports into this input field and hit apply.

--add-exports java.base/java.lang=ALL-UNNAMED
--add-exports java.desktop/sun.java2d=ALL-UNNAMED
--add-exports java.desktop/sun.awt=ALL-UNNAMED

add exports

The project can now be successfully run by clicking the green triangle in the top right hand corner.

green triangle play

About

A guide to using JOGL with JetBrains IDEs

Topics

Resources

License

Stars

Watchers

Forks