:wrench: LibGDX/LWJGL tutorials and examples

Overview

lwjgl-basics is a minimal shader-based library for 2D LWJGL sprite games. It provides essential utilities for handling textures, shaders, and sprite rendering.

For a large game project, a platform like LibGDX may be more suitable.

The source code is hosted on GitHub.

OpenGL & Shader Tutorials

The Wiki also hosts various OpenGL and GLSL tutorials:
https://github.com/mattdesl/lwjgl-basics/wiki

Installing the API

The best way to install the API is to use Eclipse and EGit (or another IDE with Git support) to pull the most recent source code. Included in the lib and native folder is a distribution of LWJGL 2.8.5, as well as an Eclipse project with class path set up for you. You can download newer versions of LWJGL from their downloads page.

Alternatively, you can download the full library as a ZIP:

ZIP

Then, simply open the Eclipse project to start testing. Ensure your LWJGL JARs and natives have been set correctly in Eclipse, NetBeans or IntelliJ, and include lwjgl-basics as a class library. lwjgl-basics also uses PNGDecoder.jar as a dependency, which can be downloaded here.

See the tests package to get started with some basic examples.

Credits

Comments
  • For lwjgl-basics tutorial, Shader 6

    For lwjgl-basics tutorial, Shader 6

    Hey Matt, the Java & LWJGL link Shader 6 for Normal Mapping just links to the same URL of the tutorial when it's clicked on. Would love if you added the source code. Thanks. Edit: Also, I'm trying not to use libgdx, that's why I ask :).

    opened by gannonprudhomme 1
  • PerspectiveCamera usage.

    PerspectiveCamera usage.

    How can I draw trails with perspective camera? I tried to add next lines to SwipeTriStrip draw() method :

           Vector2 point = tristrip.get(i);
                Vector2 tc = texcoord.get(i);
               point3.set(point.x, point.y, 0f);
                cam.unproject(point3);
                tc3.set(tc, 0f);
                cam.unproject(tc3);
                gl20.color(color.r, color.g, color.b, color.a);
                gl20.texCoord(tc3.x, tc3.z);
                gl20.vertex(point3.x, point3.y, point3.z);
    

    But it not working. Thanks in advance

    opened by vkornii 1
  • Deprecation issues

    Deprecation issues

    Just changed glGetShader and glGetProgram in ShaderProgram to glGetShaderi and glGetProgrami due to deprecation.

    Tested - works.

    According to the [LWJGL API](http://lwjgl.org/javadoc/org/lwjgl/opengl/GL20.html#glGetShader(int, int)):


    glGetShader

    public static int glGetShader(int shader,
                                  int pname)
    Deprecated. Will be removed in 3.0. Use glGetShaderi(int, int) instead.

    Overloads glGetShaderiv.


    opened by matheus23 1
  • I get a blackhole in Lesson 6: Normal Mapping

    I get a blackhole in Lesson 6: Normal Mapping

    Hi, I was trying to follow your tutorial for lighting with normal maps and I got this result

    image

    This is my shader

    in vec2 position;
    in vec2 texturePosition;
    
    out vec4 fragColor;
    
    layout(std140) uniform ubo {
      mat4 uCameraView;
      vec3 uLightPosition;
    };
    
    uniform sampler2D uTexture0;
    uniform sampler2D uTexture1;
    
    // TODO: move into the ubo
    const vec3 uLightColor = vec3(1.f);
    const vec3 uAmbientColor = vec3(0.2f);
    const float uAmbientIntensity = 1.f;
    const float uIntensity = 1.f;
    
    void main() {
      vec4 difusseColor = texture(uTexture0, texturePosition);
      vec3 normalMap = texture(uTexture1, texturePosition).rgb;
    
      vec3 normal = normalize(normalMap * 2.f - 1.f);
      vec3 lightDirection = vec3(uLightPosition.xy - position, uLightPosition.z);
      float lambert = dot(normal, normalize(lightDirection));
    
      float diffuse = sqrt(dot(lightDirection, lightDirection));
      float attenuation = 1.f / diffuse * uIntensity;
    
      fragColor = difusseColor;
      fragColor.rgb *=
        (uAmbientColor * uAmbientIntensity) + (uLightColor * lambert) * attenuation;
    }
    

    I can remove the black hole with this line of code

    float lambert = max(dot(normal, normalize(lightDirection)), 0.0f);
    

    But then I get this misaligned light without illumination where the black hole was

    image

    I think my issue might be in how I calculate the lightDirection but the way I do it above is the closest I can get to something that looks good

    opened by dortamiguel 0
  • Pull Request: The pre-multiplied projViewMatrix in SpriteBatch.

    Pull Request: The pre-multiplied projViewMatrix in SpriteBatch.

    I tried to improve the version of my last Pull Request, as you suggested:

    I removed the "updateView()" method in SpriteBatch, and changed the "updateProjection()" method into "updateMatrices()".

    I also added the utility method "storeUniformMat4(String uniform, Matrix4f mat, boolean transposed)" to ShaderProgram. This method stores a Matrix4f in the given uniform, either transposed or left as-is. This method also throws a "IllegalStateException" if "getUniformLocation()" returns -1.

    Finally I changed the VertexArrayExample and everything worked perfectly.

    Hope you take this one as an improvement, and I hope I was helpful :)

    opened by matheus23 0
  • Added the view-matrix component in the SpriteBatch.

    Added the view-matrix component in the SpriteBatch.

    The SpriteBatch now includes a view-matrix, which is present as

    • a "uniform mat4 viewMatrix" in the Default shader
    • a "protected Matrix4f viewMatrix" in the SpriteBatch class

    SpriteBatch has now the method "updateView()", which creates a FloatBuffer out of the Matrix4f viewMatrix, and then uniform with this buffer.

    The VertexArrayExample was now changed too, and includes a rotation of the whole view now. That is done by translating into the rotation point, rotating and then translating back. Finally batch.updateView() is called.

    Everything is documented with commentars, I hope you accept this Pull Request soon ;)

    opened by matheus23 0
  • I can't reproduce the light effect in ShaderLesson6

    I can't reproduce the light effect in ShaderLesson6

    I'm trying to get this effect like you describe here

    image

    But after looking at your code and sending the same projection matrix I get this effect

    image

    The NormalMap was set to vec3(1) to debug that it wasn't an issue with the normals

    What might be happening? I'm doing the same thing line by line

    opened by dortamiguel 1
  • Circular Progress Bar

    Circular Progress Bar

    Hi There is a tutorial in wiki named circular progressbar but it's empty and there's nothing useful in it. As i am new to libgdx, can anyone help me to make a simple circular progressbar tu show time?

    opened by itsOmidKarami 0
  • In ShaderLesson6 the GLSL Breakdown, should pass to gl_FragColor

    In ShaderLesson6 the GLSL Breakdown, should pass to gl_FragColor

    In ShaderLesson6, section GLSL Breakdown, the last sentence, the description makes a error, it should be gl_FragColor, but it is written to gl_FragCoord

    Next, we calculate the Intensity and FinalColor, and pass it to gl_FragCoord. Note that we keep the alpha of the DiffuseColor in tact.

    opened by FreeBlues 0
  • off screen render using PBuffer

    off screen render using PBuffer

    I need to implement off screen rendering where I can draw without creating the Display Window. Then I would save the pixels to the file system as JPEG/PNG image.

    I've read on Internet that PBuffer is one lead. I created PBuffer and didn't create the Display (Display.create()) but that is not getting updated after each draw or some other operation.

    What is the way to do it or any working example of PBuffer?

    opened by kapcip 0
  • Data types in Shaders

    Data types in Shaders

    Hello mattdesl,

    I noticed a mistake in your Intro to Shaders. You wrote that integer vector datatypes can be used as vec3i for example, but the actual data type name for them are ivec3, as stated in the OpenGL wiki.

    Thanks that you made this good resource on OpenGL 2D rendering. I'm still coming back to it :+1: :)

    (I dont know how to edit the wiki atm, I'm too dumb apparently)

    opened by matheus23 0
Owner
Matt DesLauriers
Matt DesLauriers
HackLights - Simple framebuffer based lighting engine for libGDX

HackLights Simple framebuffer based lighting engine for libGDX. Example See: Sample Code Sample Light Images: Installation Open or create gradle.prope

Ali Asif Khan 13 Dec 5, 2022
It's a particle system only appliaction. Made with LWJGL (OpenGL and GLFW for Java) and ImGui.

ParticleParty It's a particle system only appliaction. Made with LWJGL (OpenGL and GLFW for Java) and ImGui. How To Use Move the camera with ctrl + W/

Ahmet Aydogan 2 Jan 8, 2022
LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan), audio (OpenAL), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR) applications.

LWJGL - Lightweight Java Game Library 3 LWJGL (https://www.lwjgl.org) is a Java library that enables cross-platform access to popular native APIs usef

Lightweight Java Game Library 4k Dec 29, 2022
[LEGACY] LWJGL 2.X - The Lightweight Java Game Library.

[LEGACY] LWJGL - Lightweight Java Game Library WARNING This is the repository of the original LWJGL, which is no longer actively maintained. Unless yo

Lightweight Java Game Library 529 Dec 26, 2022
using LWJGL to make a mini minecraft (mac also can run)

MineCraft Mini Features MineCraft Lite in Java and OpenGL Physics simulation, water simulation Perlin noise algorithm to generate maps Directional flo

null 1 Jan 4, 2022
A Java Game Engine created in Java with LWJGL!

?? Suffler Engine Suffler Game Engine is an engine created in java using OpenGL to Graphics. Currently being developed at Eclipse, and Visual Studio C

Suffler Engine 2 Jul 23, 2022
Jetserver is a high speed nio socket based multiplayer java game server written using Netty and Mike Rettig's Jetlang.It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols.

Note New version of Jetserver is called Nadron and is in a new netty 4 branch of this same repo. JetServer is a java nio based server specifically des

Abraham Menacherry 1.2k Dec 14, 2022
With the games: brick breakers, tic-tac-toe, snake and tetris With the apps: calculator, stopwatch and text editor Themes, and hyperlinks

Game-Launcher --------------------- ABOUT THE GAME LAUNCHER ------------------------- With the games: brick breakers, tic-tac-toe, snake and tetris Wi

João Devesa 2 Dec 26, 2021
please read README to see how to play this. and star me to help me! this is very helpful and thanksful for me.

Sharustry Mod Browser / 모드 브라우저로 다운로드하기 Only possible with 124 or higher, only can download "latest" release 124 버전 이상에서만 가능하고, 오직 가장 최근의 정식 릴리즈만 다운로드

Sharlotte 51 Nov 23, 2022
A fairly Simple Game made in Java,You can adopt Pets, name them, and take care of them for XpPoints and level up!

Introducing PetGame! A simple console based game made by @denzven in Java ☕ About the Game PetGame is my first big project in Java, the rules are simp

Denzven 11 Jun 7, 2022
Quick and dirty framework for on-the-fly patching of classes via the java attach api and transformers.

Nuclear Quick and easy framework for on the fly patching of running java applications. Inspiration from an idea of an injectable minecraft cheat. What

0x150 8 Dec 28, 2021
This minecraft plugin adds @a, @p, and @r to EssentialsX Commands! Works with command block and console aswell!

EssentialsX-Target-Selectors This minecraft plugin adds @a, @p, and @r to EssentialsX Commands! Works with command block and console aswell! Usage: Ju

null 6 Dec 7, 2022
A data dumper and typing generator for the KubeJS functions, constants and classes.

ProbeJS A data dumper and typing generator for the KubeJS functions, constants and classes. Great thanks to @DAmNRelentless, @LatvianModder and @yeste

Li Junyu 13 May 25, 2022
Konas Client de-obfuscated and manually remaped by Gopro336, Perry, and other based people

Konas-Deobf-Remap This project doesent really have a purpose anymore now that the real source code has leaked (this is a higher version tho) Deobfusca

null 52 Dec 13, 2022
Cubic Skies reworks clouds and weather to make them 3D and localized, respectively. EXTREMELY WIP

Cubic Skies Cubic Skies is my second mod, and the first one to change vanilla gameplay instead of just the visuals. The mod's clouds and weather is ba

Nuclear Chaos 3 Sep 7, 2021
An experimental toolset for Unity asset and asset bundle files.

DisUnity An experimental command-line toolset for Unity asset and asset bundle files written in Java, mostly designed for extraction. Download The lat

null 2.6k Jan 6, 2023
A Java game development framework that deploys to JVM, HTML5, Android and iOS.

PlayN PlayN is a cross-platform Java game development library written in Java that targets HTML5 browsers (via GWT), desktop JVMs, Android and iOS dev

null 237 Dec 9, 2022
🗺️ Minecraft map editor and mod

A Minecraft Map Editor... that runs in-game! With selections, schematics, copy and paste, brushes, and scripting! Use it in creative, survival in sing

EngineHub 2.7k Jan 1, 2023
A fast, customizable and compatible open source server for Minecraft: Java Edition

Glowstone A fast, customizable and compatible open source server for Minecraft: Java Edition. Introduction Glowstone is a lightweight, from scratch, o

Glowstone Project 1.7k Dec 31, 2022