added ObjectGlTexColor, tweaked shaders
This commit is contained in:
parent
58e94314cc
commit
7f491ad597
@ -1,10 +1,10 @@
|
||||
#version 330 core
|
||||
|
||||
in vec3 Color;
|
||||
in vec3 color;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(Color, 1.0f);
|
||||
FragColor = vec4(color, 1.0f);
|
||||
}
|
@ -3,10 +3,12 @@
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
|
||||
out vec3 Color;
|
||||
out vec3 color;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
Color = aColor;
|
||||
gl_Position = transform * vec4(aPos, 1.0);
|
||||
color = aColor;
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
#version 330 core
|
||||
|
||||
in vec3 Color;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(Color, 1.0f);
|
||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord)), 0.5);
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec3 aTexCoord;
|
||||
|
||||
out vec3 Color;
|
||||
out vec3 texCoord;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
Color = aColor;
|
||||
gl_Position = transform * vec4(aPos, 1.0);
|
||||
texCoord = aTexCoord;
|
||||
}
|
@ -3,12 +3,11 @@ out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
in vec4 position;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord.x, -TexCoord.y)), position.x * position.y);
|
||||
FragColor = Color * mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.5);
|
||||
}
|
@ -1,18 +1,16 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
layout (location = 2) in vec3 aTexCoord;
|
||||
|
||||
out vec3 ourColor;
|
||||
out vec2 TexCoord;
|
||||
out vec4 position;
|
||||
out vec3 texCoord;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transform * vec4(aPos, 1.0);
|
||||
ourColor = aColor;
|
||||
TexCoord = aTexCoord;
|
||||
position = gl_Position;
|
||||
Color = aColor;
|
||||
texCoord = aTexCoord;
|
||||
}
|
@ -2,6 +2,7 @@ package engine;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.ObjectGl;
|
||||
import engine.object.ObjectGlColor;
|
||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
@ -131,7 +132,7 @@ public class Engine {
|
||||
engine.init();
|
||||
|
||||
// Add objects to render
|
||||
ObjectGl cube = new ObjectGl(-0.5f,0.5f,0.0f,1.0f,1.0f);
|
||||
ObjectGl cube = new ObjectGlColor(-0.5f,0.5f,0.0f,1.0f,1.0f, new float[] {0.2f, 0.2f, 0.8f});
|
||||
engine.add_objectGl(cube);
|
||||
|
||||
while(engine.isRunning()){
|
||||
|
@ -6,18 +6,10 @@ import engine.graphics.VertexArray;
|
||||
import engine.math.Matrix4f;
|
||||
|
||||
public class ObjectGlColor extends ObjectGl{
|
||||
|
||||
public ObjectGlColor(float x, float y, float z, float h, float w, float[] color) {
|
||||
super();
|
||||
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, null);
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
this.shader.enable();
|
||||
this.vertexArray.render();
|
||||
this.shader.disable();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public class ObjectGlTex extends ObjectGl{
|
||||
|
||||
List<Texture> textures;
|
||||
protected List<Texture> textures;
|
||||
|
||||
public ObjectGlTex(){
|
||||
|
||||
@ -22,13 +22,29 @@ public class ObjectGlTex extends ObjectGl{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||
|
||||
// TODO tex
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
textures.add(new Texture(path, count));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
this.shader.enable();
|
||||
|
||||
this.shader.setUniformMat4f("transform", this.transform);
|
||||
|
||||
for (Texture t : textures){
|
||||
t.bind();
|
||||
}
|
||||
|
||||
this.vertexArray.render();
|
||||
|
||||
for (Texture t : textures){
|
||||
t.unbind();
|
||||
}
|
||||
|
||||
this.shader.disable();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package engine.object;
|
||||
|
||||
import engine.graphics.Texture;
|
||||
import engine.math.Primitive;
|
||||
import engine.graphics.Shader;
|
||||
import engine.graphics.VertexArray;
|
||||
@ -15,6 +16,10 @@ public class ObjectGlTexColor extends ObjectGlTex{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
|
||||
|
||||
// TODO Create texture
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
textures.add(new Texture(path, count));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user