Shaders modif
This commit is contained in:
@ -3,6 +3,8 @@ package engine.object;
|
||||
import engine.graphics.*;
|
||||
import engine.math.*;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -30,6 +32,8 @@ public class ObjectGl {
|
||||
private float height;
|
||||
private float scalingFactor;
|
||||
|
||||
public boolean useTime;
|
||||
|
||||
private Texture texture;
|
||||
|
||||
/**
|
||||
@ -57,15 +61,17 @@ public class ObjectGl {
|
||||
this.texture = new Texture(tex, 0);
|
||||
}
|
||||
|
||||
this.vertexArray = new VertexArray(Primitive.createRectangle(z, w, h), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
|
||||
|
||||
this.zPos = z;
|
||||
this.height = h;
|
||||
this.width = w;
|
||||
|
||||
this.vertexArray = new VertexArray(Primitive.createRectangle(this.zPos, this.width, this.height), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
|
||||
|
||||
this.scalingFactor = size;
|
||||
this.transform = Matrix4f.identity();
|
||||
this.scale(new Vector3f(size, size,1f));
|
||||
this.stick_state = DEFAULT;
|
||||
this.useTime = false;
|
||||
|
||||
// use different shader for each set of option
|
||||
if (tex == null && color == null){
|
||||
@ -177,6 +183,29 @@ public class ObjectGl {
|
||||
this.setTextureWrap(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new shader to be used by this object
|
||||
* @param vert path to glsl Vertex Shader
|
||||
* @param frag path to glsl Fragment Shader
|
||||
*/
|
||||
public void setShader(String vert, String frag){
|
||||
this.shader = new Shader(vert, frag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new Color for the object if the shader do not use the color attrib this will make no change.
|
||||
* @param color Vector3f r,g,b format
|
||||
*/
|
||||
public void setColor(Vector3f color){
|
||||
float[] colorBuffer = new float[] {
|
||||
color.x, color.y, color.z,
|
||||
color.x, color.y, color.z,
|
||||
color.x, color.y, color.z,
|
||||
color.x, color.y, color.z
|
||||
};
|
||||
this.vertexArray = new VertexArray(Primitive.createRectangle(this.zPos, this.width, this.height), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap);
|
||||
}
|
||||
|
||||
private void setTextureWrap(float[] texture){
|
||||
this.vertexArray.swapTextureBufferObject(texture);
|
||||
}
|
||||
@ -189,9 +218,12 @@ public class ObjectGl {
|
||||
* Do shader binding, texture binding and vertexArray drawing
|
||||
*/
|
||||
public void render(){
|
||||
|
||||
this.shader.enable();
|
||||
if (this.texture != null) this.texture.bind();
|
||||
|
||||
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
|
||||
|
||||
this.shader.setUniformMat4f("projection", projection);
|
||||
this.shader.setUniformMat4f("view", view);
|
||||
this.shader.setUniformMat4f("transform", this.transform);
|
||||
|
Reference in New Issue
Block a user