Shaders
This is a WIP project - Expect breaking changes to occur.
Overview
Everything is handled by engine/graphics/shader.java, using:
You can read more about these, by clicking the links above.
The Shader class is responsible for loading, compiling,
and managing the shaders used in the rendering process.
It provides methods for setting uniform variables and binding the shader for use in rendering.
public void create() {
programID = GL20.glCreateProgram();
vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
. . .
}Getters and Setters
The Shader class also includes getters and setters for the shader program ID, vertex shader ID,
and fragment shader ID, allowing for easy access and management of the shader resources.
getUniformLocation()
public int getUniformLocation(String name) {
return GL20.glGetUniformLocation(programID, name);
}setUniform()
public void setUniform(String name, float value) {
GL20.glUniform1f(getUniformLocation(name), value);
}
public void setUniform(String name, int value) {
GL20.glUniform1i(getUniformLocation(name), value);
}
public void setUniform(String name, boolean value) {
GL20.glUniform1i(getUniformLocation(name), value ? 1 : 0);
}
public void setUniform(String name, Vector2f value) {
GL20.glUniform2f(getUniformLocation(name), value.x, value.y);
}
public void setUniform(String name, Vector3f value) {
GL20.glUniform3f(getUniformLocation(name), value.x, value.y, value.z);
}
public void setUniform(String name, Matrix4f value) {
FloatBuffer matrix = MemoryUtil.memAllocFloat(Matrix4f.SIZE * Matrix4f.SIZE);
matrix.put(value.getAll()).flip();
GL20.glUniformMatrix4fv(getUniformLocation(name), true, matrix);
}Last updated on