Correct frag shader when using texture + color

This commit is contained in:
Antoine 2021-05-21 19:51:29 +02:00
parent 770d134722
commit 574e31e02d
3 changed files with 6 additions and 12 deletions

View File

@ -9,5 +9,5 @@ uniform sampler2D texture1;
void main() void main()
{ {
FragColor = texture(texture1, texCoord) * color; FragColor = mix(texture(texture1, texCoord), color, 0.5);
} }

View File

@ -151,7 +151,7 @@ public class Engine {
public static void main(String[] args) { public static void main(String[] args) {
Engine engine = new Engine(); Engine engine = new Engine();
int speed = 2 ; //vitesse déplacement Object int speed = 10 ; //vitesse déplacement Object
engine.init(); engine.init();
// Add objects to render // Add objects to render
@ -205,13 +205,7 @@ public class Engine {
if(engine.shouldClose()) engine.setRunning(false); if(engine.shouldClose()) engine.setRunning(false);
} }
} }
// public static void input(ObjectGl token, int speed) {
// if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
// if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
// if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
// if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
// }
private static void gamepadInput(ObjectGl token, int speed) { private static void gamepadInput(ObjectGl token, int speed) {
ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1); ByteBuffer gamepadButton = glfwGetJoystickButtons(GLFW_JOYSTICK_1);
FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1); FloatBuffer gamepadAxes = glfwGetJoystickAxes(GLFW_JOYSTICK_1);
@ -287,5 +281,4 @@ public class Engine {
token.setTextureWrap(178,0,62,82); token.setTextureWrap(178,0,62,82);
} }
} }
} }

View File

@ -32,7 +32,7 @@ public class ObjectGl {
} }
/** /**
* Create a rectangle shape * Create a rectangle shape, use setTextureWrap to correctly align the texture with the model
* @param z depth of your model the larger it is the more it will be "close" to the camera * @param z depth of your model the larger it is the more it will be "close" to the camera
* @param h height of the rectangle * @param h height of the rectangle
* @param w width of the rectangle * @param w width of the rectangle
@ -112,6 +112,7 @@ public class ObjectGl {
} }
public void setTextureWrap(float x, float y, float w, float h){ public void setTextureWrap(float x, float y, float w, float h){
// TODO set sticky property
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h)); this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h));
int texWidth = this.texture.getWidth(); int texWidth = this.texture.getWidth();
int texHeight = this.texture.getHeight(); int texHeight = this.texture.getHeight();
@ -128,7 +129,7 @@ public class ObjectGl {
this.setTextureWrap(result); this.setTextureWrap(result);
} }
public void setTextureWrap(float[] texture){ private void setTextureWrap(float[] texture){
this.vertexArray.swapTextureBufferObject(texture); this.vertexArray.swapTextureBufferObject(texture);
} }