made meshes tintable
This commit is contained in:
parent
80a28a15af
commit
18fc57b6a5
|
@ -2,6 +2,7 @@ package com.danitheskunk.skunkworks.backends.gl;
|
|||
|
||||
import com.danitheskunk.skunkworks.Vec2f;
|
||||
import com.danitheskunk.skunkworks.Vec3f;
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.BaseRenderContext3D;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.Mesh;
|
||||
|
||||
|
@ -9,21 +10,33 @@ import static org.lwjgl.opengl.GL46.*;
|
|||
|
||||
public class RenderContext3D extends BaseRenderContext3D {
|
||||
private final int texCoordIndex;
|
||||
private final int tintIndex;
|
||||
private TextureAtlas textureAtlas;
|
||||
|
||||
public RenderContext3D(int texCoordIndex) {
|
||||
public RenderContext3D(int texCoordIndex, int tintIndex) {
|
||||
this.texCoordIndex = texCoordIndex;
|
||||
this.tintIndex = tintIndex;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderMesh(Mesh mesh) {
|
||||
renderMesh(mesh, Color.WHITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderMesh(Mesh mesh, Color tint) {
|
||||
var tex = (Texture) mesh.getTexture();
|
||||
|
||||
var texArea = tex.getTexArea();
|
||||
var texOff = Vec2f.div(texArea.getPos(), textureAtlas.getSize());
|
||||
var texMult = Vec2f.div(texArea.getSize(), textureAtlas.getSize());
|
||||
|
||||
glUniform4f(tintIndex,
|
||||
tint.getR() / 255.0f,
|
||||
tint.getG() / 255.0f,
|
||||
tint.getB() / 255.0f,
|
||||
tint.getA() / 255.0f
|
||||
);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(int i = 0; i < mesh.getTriangleCount(); ++i) {
|
||||
|
|
|
@ -40,10 +40,11 @@ public class Window extends BaseWindow {
|
|||
#version 450
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
layout(binding = 0) uniform sampler2D tex;
|
||||
layout(location = 5) uniform vec4 tint;
|
||||
out vec4 color;
|
||||
void main() {
|
||||
//color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f);
|
||||
color = texture(tex, texCoord);
|
||||
color = texture(tex, texCoord) * tint;
|
||||
//color = vec4(0.0, texCoord.xy, 1.0);
|
||||
//color = vec4(1.0, texCoord.x / 2, 1.0, 1.0);
|
||||
}
|
||||
|
@ -208,12 +209,11 @@ public class Window extends BaseWindow {
|
|||
program.getUniformLocation("tint")
|
||||
);
|
||||
|
||||
renderContext3D = new RenderContext3D(program.getAttribLocation(
|
||||
"texCoord"));
|
||||
renderContext3D = new RenderContext3D(program3D.getAttribLocation(
|
||||
"texCoord"), program3D.getUniformLocation("tint"));
|
||||
renderContext3D.setTextureAtlas(textureAtlas);
|
||||
|
||||
glProgramUniform2f(
|
||||
program.getProgram(),
|
||||
glProgramUniform2f(program.getProgram(),
|
||||
program.getUniformLocation("windowSize"),
|
||||
size.getX(),
|
||||
size.getY()
|
||||
|
@ -312,8 +312,7 @@ public class Window extends BaseWindow {
|
|||
|
||||
|
||||
private void mouseButtonCallback(
|
||||
@SuppressWarnings("unused") long window, int button, int action,
|
||||
@SuppressWarnings(
|
||||
@SuppressWarnings("unused") long window, int button, int action, @SuppressWarnings(
|
||||
"unused") int mods
|
||||
) {
|
||||
switch(action) {
|
||||
|
@ -385,8 +384,7 @@ public class Window extends BaseWindow {
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, framebufferTex);
|
||||
glProgramUniform2f(
|
||||
programScaler.getProgram(),
|
||||
glProgramUniform2f(programScaler.getProgram(),
|
||||
programScaler.getUniformLocation("windowSize"),
|
||||
windowSize.getX(),
|
||||
windowSize.getY()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.danitheskunk.skunkworks.gfx.threedee;
|
||||
|
||||
import com.danitheskunk.skunkworks.Vec3f;
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
|
||||
public interface IRenderContext3D {
|
||||
void renderTriangle(Vec3f p1, Vec3f p2, Vec3f p3);
|
||||
void renderMesh(Mesh mesh);
|
||||
void renderMesh(Mesh mesh, Color tint);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue