swapTexWrap added
This commit is contained in:
parent
859344b131
commit
4fc87e7b08
@ -8,5 +8,5 @@ uniform sampler2D texture1;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(texture1, vec2(-texCoord.y, -texCoord.x));
|
FragColor = texture(texture1, texCoord);
|
||||||
}
|
}
|
@ -166,6 +166,7 @@ public class Engine {
|
|||||||
ObjectGlTex smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path2, Primitive.stdTexWrap);
|
ObjectGlTex smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path2, Primitive.stdTexWrap);
|
||||||
engine.add_objectGl(smiley2);
|
engine.add_objectGl(smiley2);
|
||||||
smiley2.translate(new Vector3f(0.0f,0.0f,5.0f));
|
smiley2.translate(new Vector3f(0.0f,0.0f,5.0f));
|
||||||
|
float[] texWrap = Primitive.upperHalfTexWrap;
|
||||||
|
|
||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
long lastFrame;
|
long lastFrame;
|
||||||
@ -173,11 +174,13 @@ public class Engine {
|
|||||||
boolean nextFrame = false;
|
boolean nextFrame = false;
|
||||||
|
|
||||||
while(engine.isRunning()){
|
while(engine.isRunning()){
|
||||||
|
double time = glfwGetTime();
|
||||||
lastFrame = System.currentTimeMillis();
|
lastFrame = System.currentTimeMillis();
|
||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
|
|
||||||
input(smiley, speed);
|
input(smiley, speed);
|
||||||
// input(smiley2, speed);
|
// input(smiley2, speed);
|
||||||
|
smiley.setTextureWrap(0,0,200,200);
|
||||||
|
|
||||||
//essential part v
|
//essential part v
|
||||||
engine.update();
|
engine.update();
|
||||||
|
@ -64,4 +64,12 @@ public class Texture {
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWidth(){
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight(){
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,16 @@ public class VertexArray {
|
|||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void swapVertexBufferObject(float[] vertices){
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(vertices), GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void swapTextureBufferObject(float [] texture){
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, TBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, BufferUtils.createFloatBuffer(texture), GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
glBindVertexArray(this.VAO);
|
glBindVertexArray(this.VAO);
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,30 @@ public class Primitive {
|
|||||||
|
|
||||||
public static float[] createRectangle(float x, float y, float z, float w, float h){
|
public static float[] createRectangle(float x, float y, float z, float w, float h){
|
||||||
return new float[] {
|
return new float[] {
|
||||||
x , y , z,
|
x , y , z, // Haut gauche
|
||||||
x + w, y , z,
|
x + w, y , z, // Haut droit
|
||||||
x + w, y - h, z,
|
x + w, y - h, z, // Bas droit
|
||||||
x , y - h, z
|
x , y - h, z // Bas gauche
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chaque point correspond à un vertex de la primite le reste est interpolé
|
||||||
|
*/
|
||||||
public static float[] stdTexWrap = new float[] {
|
public static float[] stdTexWrap = new float[] {
|
||||||
1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f,
|
0.0f, 0.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
0.0f, 1.0f
|
0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static float[] upperHalfTexWrap = new float[] {
|
||||||
|
0.0f, 0.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
1.0f, 0.5f,
|
||||||
|
0.0f, 0.5f
|
||||||
|
};
|
||||||
|
|
||||||
public static byte[] rectangle_indices = new byte[] {
|
public static byte[] rectangle_indices = new byte[] {
|
||||||
0, 1, 3,
|
0, 1, 3,
|
||||||
1, 2, 3
|
1, 2, 3
|
||||||
|
@ -5,6 +5,7 @@ import engine.graphics.Shader;
|
|||||||
import engine.graphics.Texture;
|
import engine.graphics.Texture;
|
||||||
import engine.graphics.VertexArray;
|
import engine.graphics.VertexArray;
|
||||||
import engine.math.Matrix4f;
|
import engine.math.Matrix4f;
|
||||||
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,6 +36,23 @@ public class ObjectGlTex extends ObjectGl{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTextureWrap(float x, float y, float w, float h){
|
||||||
|
int texWidth = this.textures.get(0).getWidth();
|
||||||
|
int texHeight = this.textures.get(0).getHeight();
|
||||||
|
float[] result = {
|
||||||
|
x / texWidth, y / texHeight,
|
||||||
|
x + w / texWidth, y / texHeight,
|
||||||
|
x + w / texWidth, y + h / texHeight,
|
||||||
|
x / texWidth, y + h / texHeight,
|
||||||
|
};
|
||||||
|
// TODO scaling object
|
||||||
|
this.setTextureWrap(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextureWrap(float[] texture){
|
||||||
|
this.vertexArray.swapTextureBufferObject(texture);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
this.shader.enable();
|
this.shader.enable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user