Basic esample with shaders and camera (lwjgl3)

Started by msx, January 29, 2015, 12:25:30

Previous topic - Next topic

msx

Hello there.. I tryed as best as i could but failed to put together an example showing the use of basic shaders and a perspective camera with lwjgl3. I've picked up part of stuff from various examples but couldn't get it to work..
Do you have a working minimal example?

Thanks

abcdef

The basics are as follows

#version 330

layout(location = 0) in vec3 vertex;
layout(location = 1) in vec4 color;

uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;

smooth out vec4 theColor;

void main()
{
    mat4 mvpMatrix=projectionMatrix*viewMatrix*modelMatrix;
    gl_Position = mvpMatrix*vec4(vertex,1.0);
    theColor = color;
}


Your model would provide the model matrix (transformation to move your model to the right place in the world)
Your camera class would pass the view matrix, as it changes you would need to update the shader
You perspective matrix would typically be fixed (unless you change screen resolution or screen size)

There isn't too much else to show you :) The code is opengl 3.2+ but it would be trivial to change it to < than. You would just change the two layout lines to the format you want.

msx

thanks! that's one step.. i have explained myself bad, i'd need a whole example with the java code :)
I've tryed to use a Camera class found in old lwjgl, which has methods to create the model and the view matrix (setLookAt and setFrustumPerspective, i think). Then i tried to render something but the window stay black. Since the problem could be anywhere (shaders, model or camera position, clipping, culling, matrix math, etc), i wanted a clean working base to start with.. I hope i'm not asking too much.. :)

abcdef

maybe show us what you have and we can tell you what's wrong?

Posting the whole solution isn't really helping you (and nearly everyone won't just have a simple example to post), I think you maybe asking much :)

I'd recommend starting basic and building up, the old wiki (2.9 lwjgl) has some good tutorials on there which would work fine with lwjgl 3. Just take the getting started code and adapt