ObjectGl, ObjectGlColor, ObjectGlTex added
This commit is contained in:
parent
b7de1556cc
commit
c6181c96fe
8
shaders/ObjectGl/frag.glsl
Normal file
8
shaders/ObjectGl/frag.glsl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
8
shaders/ObjectGl/vert.glsl
Normal file
8
shaders/ObjectGl/vert.glsl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(aPos, 1.0);
|
||||||
|
}
|
10
shaders/ObjectGlColor/frag.glsl
Normal file
10
shaders/ObjectGlColor/frag.glsl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in vec3 Color;
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(Color, 1.0f);
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
layout (location = 1) in vec3 aColor;
|
layout (location = 1) in vec3 aColor;
|
||||||
|
|
||||||
out vec4 position;
|
out vec3 Color;
|
||||||
out vec4 Color;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos, 1.0);
|
gl_Position = vec4(aPos, 1.0);
|
||||||
Color = vec4(aColor, 1.0f);
|
Color = aColor;
|
||||||
}
|
}
|
10
shaders/ObjectGlTex/frag.glsl
Normal file
10
shaders/ObjectGlTex/frag.glsl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in vec3 Color;
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragColor = vec4(Color, 1.0f);
|
||||||
|
}
|
12
shaders/ObjectGlTex/vert.glsl
Normal file
12
shaders/ObjectGlTex/vert.glsl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aColor;
|
||||||
|
|
||||||
|
out vec3 Color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(aPos, 1.0);
|
||||||
|
Color = aColor;
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec4 position;
|
|
||||||
in vec4 Color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
FragColor = Color;
|
|
||||||
}
|
|
@ -31,6 +31,15 @@ public class Primitive {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float[] createRectangle(float x, float y, float z, float w, float h){
|
||||||
|
return new float[] {
|
||||||
|
x , y , z,
|
||||||
|
x + h, y , z,
|
||||||
|
x + h, y + w, z,
|
||||||
|
x , y + w, z
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static float[] triangle = new float[] {
|
public static float[] triangle = new float[] {
|
||||||
0.0f, 0.5f, 0.0f,
|
0.0f, 0.5f, 0.0f,
|
||||||
0.5f, -0.5f, 0.0f,
|
0.5f, -0.5f, 0.0f,
|
||||||
|
@ -25,7 +25,7 @@ public class Scene {
|
|||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
||||||
this.indices = indices;
|
this.indices = indices;
|
||||||
this.shader = new Shader(vertPath, fragPath);
|
this.shader = new Shader(vertPath, fragPath);
|
||||||
this.vertexArray = new VertexArray(this.vertices, this.indices);
|
this.vertexArray = new VertexArray(this.vertices, this.indices, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scene(String vertPath, String fragPath, float[] vertices, byte[] indices, float[] color, float[] texture){
|
public Scene(String vertPath, String fragPath, float[] vertices, byte[] indices, float[] color, float[] texture){
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package engine.graphics;
|
package engine.graphics;
|
||||||
|
|
||||||
import engine.utils.BufferUtils;
|
import engine.utils.BufferUtils;
|
||||||
import org.lwjgl.opengl.GL15;
|
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.opengl.GL15.*;
|
import static org.lwjgl.opengl.GL15.*;
|
||||||
@ -12,46 +11,6 @@ public class VertexArray {
|
|||||||
private int VAO ,VBO, EBO, CBO, TBO;
|
private int VAO ,VBO, EBO, CBO, TBO;
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
public VertexArray(float[] vertices, byte[] indices){
|
|
||||||
count = indices.length;
|
|
||||||
// VERTEX ARRAY OBJECT
|
|
||||||
VAO = glGenVertexArrays();
|
|
||||||
glBindVertexArray(VAO);
|
|
||||||
|
|
||||||
// VERTEX BUFFER OBJECT
|
|
||||||
createVertexBufferObject(vertices);
|
|
||||||
|
|
||||||
EBO = glGenBuffers();
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
||||||
GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtils.createByteBuffer(indices), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexArray(float[] vertices, byte[] indices, float[] color) {
|
|
||||||
count = indices.length;
|
|
||||||
// VERTEX ARRAY OBJECT
|
|
||||||
VAO = glGenVertexArrays();
|
|
||||||
glBindVertexArray(VAO);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
// VERTEX BUFFER OBJECT
|
|
||||||
createVertexBufferObject(vertices);
|
|
||||||
// COLOR BUFFER OBJECT
|
|
||||||
createColorBufferObject(color);
|
|
||||||
|
|
||||||
EBO = glGenBuffers();
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtils.createByteBuffer(indices), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public VertexArray(float[] vertices, byte[] indices, float[] color, float[] texture) {
|
public VertexArray(float[] vertices, byte[] indices, float[] color, float[] texture) {
|
||||||
count = indices.length;
|
count = indices.length;
|
||||||
// VERTEX ARRAY OBJECT
|
// VERTEX ARRAY OBJECT
|
||||||
@ -63,9 +22,9 @@ public class VertexArray {
|
|||||||
// VERTEX BUFFER OBJECT
|
// VERTEX BUFFER OBJECT
|
||||||
createVertexBufferObject(vertices);
|
createVertexBufferObject(vertices);
|
||||||
// COLOR BUFFER OBJECT
|
// COLOR BUFFER OBJECT
|
||||||
createColorBufferObject(color);
|
if (color != null) createColorBufferObject(color);
|
||||||
// TEXTURE BUFFER OBJECT
|
// TEXTURE BUFFER OBJECT
|
||||||
createTextureBufferObject(texture);
|
if (texture != null) createTextureBufferObject(texture);
|
||||||
|
|
||||||
EBO = glGenBuffers();
|
EBO = glGenBuffers();
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
package engine;
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.Primitive;
|
||||||
import engine.graphics.VertexArray;
|
import engine.graphics.VertexArray;
|
||||||
import engine.graphics.Shader;
|
import engine.graphics.Shader;
|
||||||
import engine.math.Matrix4f;
|
import engine.math.Matrix4f;
|
||||||
import engine.math.Vector3f;
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class ObjectGl {
|
public class ObjectGl {
|
||||||
|
|
||||||
private VertexArray vertexArray;
|
protected VertexArray vertexArray;
|
||||||
private Shader shader;
|
protected Shader shader;
|
||||||
private Matrix4f transform;
|
protected Matrix4f transform;
|
||||||
|
|
||||||
public ObjectGl(float x, float y, float h, float w){
|
public ObjectGl(float x, float y, float z, float h, float w){
|
||||||
// TODO Create a rectangle
|
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, null);
|
||||||
this.transform = Matrix4f.identity();
|
this.transform = Matrix4f.identity();
|
||||||
|
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTransform(){
|
public void resetTransform(){
|
||||||
@ -46,5 +51,4 @@ public class ObjectGl {
|
|||||||
this.shader.disable();
|
this.shader.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
18
src/engine/object/ObjectGlColor.java
Normal file
18
src/engine/object/ObjectGlColor.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.graphics.Shader;
|
||||||
|
|
||||||
|
public class ObjectGlColor extends ObjectGl{
|
||||||
|
|
||||||
|
public ObjectGlColor(float x, float y, float h, float w, float[] color) {
|
||||||
|
super(x, y, h, w);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
18
src/engine/object/ObjectGlTex.java
Normal file
18
src/engine/object/ObjectGlTex.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.graphics.Shader;
|
||||||
|
|
||||||
|
public class ObjectGlTex extends ObjectGl{
|
||||||
|
|
||||||
|
public ObjectGlTex(float x, float y, float h, float w, float[] texCoord) {
|
||||||
|
super(x, y, h, w);
|
||||||
|
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
this.shader.enable();
|
||||||
|
this.vertexArray.render();
|
||||||
|
this.shader.disable();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user