swapTexWrap from pixels coordinates of the source image

This commit is contained in:
Antoine
2021-05-20 20:04:16 +02:00
parent 4fc87e7b08
commit 29685f8e40
6 changed files with 29 additions and 11 deletions

View File

@ -21,6 +21,8 @@ public class ObjectGl {
public static Matrix4f view;
public float zPos;
public float width;
public float height;
public ObjectGl(){
@ -31,6 +33,8 @@ public class ObjectGl {
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
this.zPos = z;
this.width = w;
this.height = h;
}
public void resetTransform(){

View File

@ -12,5 +12,7 @@ public class ObjectGlColor extends ObjectGl{
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
this.zPos = z;
this.width = w;
this.height = h;
}
}

View File

@ -24,6 +24,8 @@ public class ObjectGlTex extends ObjectGl{
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
this.zPos = z;
this.width = w;
this.height = h;
this.setTexture(texPath);
}
@ -39,11 +41,15 @@ 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();
x /= texWidth;
w /= texWidth;
y /= texHeight;
h /= texHeight;
float[] result = {
x / texWidth, y / texHeight,
x + w / texWidth, y / texHeight,
x + w / texWidth, y + h / texHeight,
x / texWidth, y + h / texHeight,
x , y ,
x + w , y ,
x + w , y + h ,
x , y + h ,
};
// TODO scaling object
this.setTextureWrap(result);

View File

@ -17,6 +17,8 @@ public class ObjectGlTexColor extends ObjectGlTex{
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
this.zPos = z;
this.width = w;
this.height = h;
this.setTexture(texPath);
}
}