Learning Modern 3D Graphics Programming with LWJGL 3 and JOML
This project is a port of Learning Modern 3D Graphics Programming tutorials to Java using LWJGL and JOML, distributed in the hope that it will be useful. The original project, named
gltut, can be found here. Since it is needed by the tutorials, this repository also includes a partial port of the Unofficial OpenGL SDK, named
glsdk, which contains a DDS texture loader and other useful stuff.
To try the tutorials without building the source code, you can download the runnable JAR included in the Releases section. Many tutorials print messages to console: run the JAR from the command line with
java -jar jgltut.jar to view the output (also useful in case of errors).
I can't dedicate much time to this project anymore, but I will keep it updated to work with recent versions of LWJGL and JOML. I will also keep refactoring code I don't like. To suggest a feature, report bugs or general discussion use the issue tracker.
To compile and run the code, you will need:
- Java SE Development Kit 8
- LWJGL 3 (tested with 3.0.0b build 35) (will port to latest version when #205 gets fixed)
- JOML (tested with 1.8.0)
Working with different versions of LJWGL 3 or JOML may require adjustments to the code. If you are stuck with LWJGL 2, check the release v0.9.1 of this repository.
Create a new Java project using your favorite IDE, then:
- Import the source code of this repository;
lwjgl.jarto the classpath and link the LWJGL native libraries, as explained here;
- Import the source code of the JOML library (or, alternatively, build yourself a
joml.jarand add it to the classpath as in the previous step).
Finally, run the
main method of the first tutorial
integeruser.jgltut.tut01.Tut1.java and check the output in the console window. If your graphics card does not meet the minimum requirements (checked using the LWJGL helper
GL.getCapabilities().OpenGL33), the message
You must have at least OpenGL 3.3 to run this tutorial. will appear; otherwise, if no other errors show up, you can start playing with the other tutorials by running the
main method of
integeruser.jgltut.TutorialChooser.java. To quit any tutorial simply press
I decided to keep the ported code as similar as possible to the original C++ code, despite I would have done some things differently, and variable and function names are almost identical to their counterpart in the original projects. The only notable difference is the introduction of the
commons package, to collect some classes used in several parts of the project. I also decided to keep the same directory layout:
jgltut/ |-- commons/ |-- data/ |-- framework/ |-- tut01/ |------ Tut1.java |-- tut02/ |------ data/ |------ FragPosition.java |------ VertexColor.java |-- ... |-- ... |-- ... |-- tut17/ |------ data/ |------ CubePointLight.java |------ DoubleProjection.java |------ ProjectedLight.java |-- Tutorial.java |-- TutorialChooser.java jglsdk/ |-- glimg/ |-- glm/ |-- glutil/
Each tutorial loads the files it needs from the global
integeruser.jgltut.data folder or from its own
data folder. The
integeruser.jgltut.framework package contains utility code needed by multiple tutorials.
At first, the code may appear difficult to read, but after a bit of reading you will realize that it is well-grouped into logical sections. I suggest you to start by skimming through the code with methods and inner classes folded. Don't get lost in the details of the
integeruser.jglsdk module which contains only utility classes.
Extract from the
The following files are copywritten and distributed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license, as described in the "./CC BY 3.0 legalcode.txt" file. Attribution for these works is presented here: Attributed to Etory, of OpenGameArt.org: * data/seamless_rock1_small.dds Attributed to p0ss, of OpenGameArt.org: * data/concrete649_small.dds * data/dsc_1621_small.dds * data/rough645_small.dds
This project is licensed under the Attribution 4.0 International license: you can do what you want with my code, but if you want to publish some derived work I kindly ask you to simply provide a link to this repository.