ObjectGlTex & ObjectGlTexColor now working :o)
This commit is contained in:
parent
7f491ad597
commit
57b6be084d
@ -2,12 +2,11 @@
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoord;
|
||||
in vec2 texCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord)), 0.5);
|
||||
FragColor = texture(texture1, vec2(texCoord.y, -texCoord.x));
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 2) in vec3 aTexCoord;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
out vec3 texCoord;
|
||||
out vec2 texCoord;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
in vec4 color;
|
||||
in vec2 texCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = Color * mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.5);
|
||||
FragColor = texture(texture1, vec2(texCoord.y, -texCoord.x)) * color;
|
||||
}
|
@ -2,15 +2,16 @@
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec3 aTexCoord;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
out vec3 texCoord;
|
||||
out vec2 texCoord;
|
||||
out vec4 color;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transform * vec4(aPos, 1.0);
|
||||
Color = aColor;
|
||||
color = vec4(aColor, 1.0f);
|
||||
texCoord = aTexCoord;
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package engine;
|
||||
|
||||
import engine.math.Primitive;
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.ObjectGl;
|
||||
import engine.object.ObjectGlColor;
|
||||
import engine.object.ObjectGlTex;
|
||||
import engine.object.ObjectGlTexColor;
|
||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
@ -68,6 +71,10 @@ public class Engine {
|
||||
glfwSetFramebufferSizeCallback(window, resizeWindow);
|
||||
|
||||
glEnable(GL_DEPTH_TEST); // Z-Buffer
|
||||
|
||||
glEnable(GL_BLEND); // Transparence
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
System.out.println("OpenGL: " + glGetString(GL_VERSION));
|
||||
}
|
||||
@ -132,14 +139,14 @@ public class Engine {
|
||||
engine.init();
|
||||
|
||||
// Add objects to render
|
||||
ObjectGl cube = new ObjectGlColor(-0.5f,0.5f,0.0f,1.0f,1.0f, new float[] {0.2f, 0.2f, 0.8f});
|
||||
List<String> path = new ArrayList<>();
|
||||
path.add("textures/awesomeface.png");
|
||||
ObjectGlTexColor cube = new ObjectGlTexColor(-0.5f,0.5f,0.0f,1.0f,1.0f, path, Primitive.stdTexWrap, new float[] {1.0f,1.0f,1.0f});
|
||||
engine.add_objectGl(cube);
|
||||
|
||||
while(engine.isRunning()){
|
||||
|
||||
// Game logic should fit here
|
||||
cube.rotateZ(1.0f);
|
||||
cube.translate(new Vector3f(0.01f, 0.0f, 0.0f));
|
||||
|
||||
//essential part v
|
||||
engine.update();
|
||||
|
@ -1,67 +0,0 @@
|
||||
package engine;
|
||||
|
||||
import engine.graphics.Shader;
|
||||
import engine.graphics.Texture;
|
||||
import engine.graphics.VertexArray;
|
||||
import engine.math.Matrix4f;
|
||||
import engine.math.Vector3f;
|
||||
|
||||
public class Scene {
|
||||
|
||||
float[] vertices;
|
||||
float[] color;
|
||||
float[] texture;
|
||||
float[] texture2;
|
||||
Texture texture_map;
|
||||
Texture texture_map2;
|
||||
byte[] indices;
|
||||
|
||||
Matrix4f transform;
|
||||
|
||||
VertexArray vertexArray;
|
||||
Shader shader;
|
||||
|
||||
public Scene(String vertPath, String fragPath, float[] vertices, byte[] indices){
|
||||
this.vertices = vertices;
|
||||
this.indices = indices;
|
||||
this.shader = new Shader(vertPath, fragPath);
|
||||
this.vertexArray = new VertexArray(this.vertices, this.indices, null, null);
|
||||
}
|
||||
|
||||
public Scene(String vertPath, String fragPath, float[] vertices, byte[] indices, float[] color, float[] texture){
|
||||
this.vertices = vertices;
|
||||
this.indices = indices;
|
||||
this.color = color;
|
||||
this.shader = new Shader(vertPath, fragPath);
|
||||
this.texture_map = new Texture("textures/container.jpg", 0);
|
||||
this.texture = texture;
|
||||
this.texture_map2 = new Texture("textures/awesomeface.png", 1);
|
||||
this.texture2 = texture;
|
||||
this.vertexArray = new VertexArray(this.vertices, this.indices, this.color, this.texture);
|
||||
shader.setUniform1i("texture1", 0);
|
||||
shader.setUniform1i("texture2", 1);
|
||||
this.transform = Matrix4f.translate(new Vector3f(-0.1f, 0.2f, 0.0f));
|
||||
this.transform = this.transform.multiply(Matrix4f.rotateZ(90.0f));
|
||||
shader.setUniformMat4f("transform", this.transform);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
if (this.transform != null){
|
||||
this.transform = this.transform.multiply(Matrix4f.rotateZ(1.0f));
|
||||
this.transform = this.transform.multiply(Matrix4f.translate(new Vector3f(-0.001f, 0.0f, 0.0f)));
|
||||
this.transform = this.transform.multiply(Matrix4f.rotateX(1.0f));
|
||||
shader.setUniformMat4f("transform", this.transform);
|
||||
}
|
||||
this.shader.enable();
|
||||
if (this.texture_map != null){
|
||||
this.texture_map.bind();
|
||||
this.texture_map2.bind();
|
||||
}
|
||||
this.vertexArray.render();
|
||||
if (this.texture_map != null) {
|
||||
this.texture_map2.unbind();
|
||||
this.texture_map.unbind();
|
||||
}
|
||||
this.shader.disable();
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import engine.graphics.Texture;
|
||||
import engine.graphics.VertexArray;
|
||||
import engine.math.Matrix4f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectGlTex extends ObjectGl{
|
||||
@ -22,6 +23,7 @@ public class ObjectGlTex extends ObjectGl{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||
|
||||
this.textures = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
textures.add(new Texture(path, count));
|
||||
|
@ -6,6 +6,7 @@ import engine.graphics.Shader;
|
||||
import engine.graphics.VertexArray;
|
||||
import engine.math.Matrix4f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectGlTexColor extends ObjectGlTex{
|
||||
@ -16,6 +17,7 @@ public class ObjectGlTexColor extends ObjectGlTex{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
|
||||
|
||||
this.textures = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
textures.add(new Texture(path, count));
|
||||
|
Loading…
x
Reference in New Issue
Block a user