Last active
December 14, 2022 00:42
-
-
Save bploeckelman/d344ab61b8954b84745dfb344f572bcd to your computer and use it in GitHub Desktop.
Example use of LWGL in a LibGDX application to access OpenGL 4.6 features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | |
/** | |
Launches the desktop (LWJGL3) application. | |
** Need to configure the OpenGL version here ** | |
*/ | |
public class Lwjgl3Launcher { | |
public static void main(String[] args) { | |
createApplication(); | |
} | |
private static Lwjgl3Application createApplication() { | |
return new Lwjgl3Application(new Main(), getDefaultConfiguration()); | |
} | |
private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() { | |
Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration(); | |
// NOTE: 3.2 is the highest supported version on MacOS! | |
// ********************************** | |
// * configuration.useOpenGL3(true, 4, 6); // pre libgdx 1.11.0 | |
// * configuration.setOpenGLEmulation(GLEmulation.GL30, 4, 6); // since libgdx 1.11.0 | |
// ********************************** | |
configuration.setTitle("Window Title"); | |
configuration.setBackBufferConfig(8, 8, 8, 8, 16, 0, 4); | |
configuration.setWindowedMode(1280, 720); | |
configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png"); | |
return configuration; | |
} | |
} | |
// ----------------------------------------------------- | |
/** | |
Now you can use the LWJGL classes to get an more modern OpenGL functions and constants | |
*/ | |
import org.lwjgl.opengl.GL46; | |
public class GdxLwjglGl46Example { | |
private void initializeBufferObjects() { | |
buffers.vbo.positions = Gdx.gl.glGenBuffer(); | |
Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, buffers.vbo.positions); | |
Gdx.gl.glBufferData(GL20.GL_ARRAY_BUFFER, buffers.positions_size, buffers.data.positions, GL20.GL_STATIC_DRAW); | |
Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.positions); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.positions, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
buffers.vbo.colors = Gdx.gl.glGenBuffer(); | |
Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, buffers.vbo.colors); | |
Gdx.gl.glBufferData(GL20.GL_ARRAY_BUFFER, buffers.colors_size, buffers.data.colors, GL20.GL_STATIC_DRAW); | |
Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.colors); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.colors, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
buffers.vbo.density = Gdx.gl.glGenBuffer(); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.density); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.density, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
buffers.vbo.pressure = Gdx.gl.glGenBuffer(); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.pressure); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.pressure, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
buffers.vbo.forces = Gdx.gl.glGenBuffer(); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.forces); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.forces, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
buffers.vbo.velocities = Gdx.gl.glGenBuffer(); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, buffers.vbo.velocities); | |
GL46.glBufferStorage(GL46.GL_SHADER_STORAGE_BUFFER, buffers.data.velocities, GL46.GL_MAP_WRITE_BIT | GL46.GL_DYNAMIC_STORAGE_BIT); | |
GL46.glBindBuffer(GL46.GL_SHADER_STORAGE_BUFFER, 0); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 0, buffers.vbo.positions); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 1, buffers.vbo.density); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 2, buffers.vbo.pressure); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 3, buffers.vbo.forces); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 4, buffers.vbo.velocities); | |
GL46.glBindBufferBase(GL46.GL_SHADER_STORAGE_BUFFER, 5, buffers.vbo.colors); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment