Code Monkey home page Code Monkey logo

lwjgl-basics's Introduction

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

lwjgl-basics's People

Contributors

matheus23 avatar mattdesl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lwjgl-basics's Issues

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

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?

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 ๐Ÿ‘ :)

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

Creating a Camera

Im trying to make myself a little engine and these tutorials helped me a lot, but now i stuck creating an Orthographic camera.
Can some one please show me a way? (maybe @mattdesl? :))

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

Using libGdx and writing shaders without hardcoding

I tried to get it to work but it doesn't display at all. There are no compile errors.

Vertex

uniform mat4 u_progTrans;

//SpriteBatch input
attribute vec4 Position;
attribute vec2 TexCoord;
attribute vec4 Color;

//Fragment output (varying)
varying vec2 vTexCoord;
varying vec4 vColor;

//Main
void main() {
    vColor = Color;
    vTexCoord = TexCoord;
    gl_Position = u_progTrans * Position;

}

Fragment

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else 
#define LOWP
#endif

//Texture
uniform sampler2D u_texture;

//Input form vertex (varying)
varying vec2 vTexCoord;
varying LOWP vec4 vColor;

//Main
void main() {
    //Sample the texture
    vec4 texColor = texture2D(u_texture, vTexCoord);

    //Color modification
    texColor.rgb = 1.0 - texColor.rgb;

    //Output
    gl_FragColor = texColor * vColor;
}

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

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 :).

Blur a Bitmap using LerpBlur?

Thanks for the good repo. I need to apply blurring to a Bitmap object in Android in realtime. But I couldn't find a class/function that takes a Bitmap (or the int[] pixel array of bitmap) and return the resulting bitmap. Can you provide such a function?

Bitmap result = applyblur (bitmap)

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.