made rendering transparent (for obs capture) work with scaling and terminal

This commit is contained in:
DaniTheSkunk 2022-11-17 01:47:51 +00:00
parent cafd9f8132
commit 63c1def130
5 changed files with 21 additions and 11 deletions

View File

@ -62,7 +62,7 @@ public class Test extends BaseGame {
@Override @Override
protected void update(double delta) { protected void update(double delta) {
var mouse = window.getMousePos(); var mouse = window.getMousePos();
term.clear(Color.BLACK); term.clear(Color.TRANS_BLACK);
var col = window.isMouseDown(0) ? Color.RED : Color.GREEN; var col = window.isMouseDown(0) ? Color.RED : Color.GREEN;
term.setBackgroundColor(Vec2i.div(mouse, term.getFullCharSize()), col); term.setBackgroundColor(Vec2i.div(mouse, term.getFullCharSize()), col);
if(window.isMouseClicked(1)) { if(window.isMouseClicked(1)) {

View File

@ -176,10 +176,11 @@ class RenderContext extends BaseRenderContext implements IRenderContext {
tbr = Vec2i.sub(tex.getTexArea().getBottomRight(), topleft); tbr = Vec2i.sub(tex.getTexArea().getBottomRight(), topleft);
} }
glUniform3f(tintIndex, glUniform4f(tintIndex,
color.getR() / 255.0f, color.getR() / 255.0f,
color.getG() / 255.0f, color.getG() / 255.0f,
color.getB() / 255.0f color.getB() / 255.0f,
color.getA() / 255.0f
); );
//color.getA() / 255.0f); //color.getA() / 255.0f);

View File

@ -34,12 +34,16 @@ public class Window extends BaseWindow {
layout(binding = 0) uniform sampler2D tex; layout(binding = 0) uniform sampler2D tex;
layout(location = 3) uniform ivec2 texOffset; layout(location = 3) uniform ivec2 texOffset;
layout(location = 4) uniform ivec2 texSize; layout(location = 4) uniform ivec2 texSize;
layout(location = 5) uniform vec3 tint; layout(location = 5) uniform vec4 tint;
out vec4 color; out vec4 color;
void main() { void main() {
//color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f); //color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f);
//color = texture(tex, texCoord); //color = texture(tex, texCoord);
color = texelFetch(tex, ivec2(mod(texCoord, texSize)) + texOffset, 0) * vec4(tint, 1.0f); vec4 col = texelFetch(tex, ivec2(mod(texCoord, texSize)) + texOffset, 0);
if(tint.a > 0.0) {
color = col * tint;
}
} }
"""; """;
@ -61,7 +65,10 @@ public class Window extends BaseWindow {
out vec4 color; out vec4 color;
void main() { void main() {
//color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f); //color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f);
color = texture(tex, texCoord); vec4 col = texture(tex, texCoord);
if(col.a > 0.0) {
color = col;
}
//color = texelFetch(tex, ivec2(texCoord), 0); //color = texelFetch(tex, ivec2(texCoord), 0);
//color = vec4(1.0, 1.0, 1.0, 1.0); //color = vec4(1.0, 1.0, 1.0, 1.0);
//color = vec4(texCoord.xy, 0.0, 1.0); //color = vec4(texCoord.xy, 0.0, 1.0);
@ -122,11 +129,11 @@ public class Window extends BaseWindow {
glBindTexture(GL_TEXTURE_2D, framebufferTex); glBindTexture(GL_TEXTURE_2D, framebufferTex);
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RGB, GL_RGBA,
size.getX(), size.getX(),
size.getY(), size.getY(),
0, 0,
GL_RGB, GL_RGBA,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
0 0
); );
@ -229,10 +236,11 @@ public class Window extends BaseWindow {
); );
} }
//glEnd(); //glEnd();
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, windowSize.getX(), windowSize.getY()); glViewport(0, 0, windowSize.getX(), windowSize.getY());
programScaler.use(); programScaler.use();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, framebufferTex); glBindTexture(GL_TEXTURE_2D, framebufferTex);
@ -319,7 +327,7 @@ public class Window extends BaseWindow {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, size.getX(), size.getY()); glViewport(0, 0, size.getX(), size.getY());
textureAtlas.update(); textureAtlas.update();
glClearColor(0.f, 0.f, 0.f, 1.0f); glClearColor(0.f, 0.f, 0.f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
program.use(); program.use();
//glBegin(GL_TRIANGLES); //glBegin(GL_TRIANGLES);

View File

@ -12,6 +12,7 @@ public final class Color {
public final static Color YELLOW = new Color(255, 255, 0); public final static Color YELLOW = new Color(255, 255, 0);
public final static Color MAGENTA = new Color(255, 0, 255); public final static Color MAGENTA = new Color(255, 0, 255);
public final static Color CYAN = new Color(0, 255, 255); public final static Color CYAN = new Color(0, 255, 255);
public final static Color TRANS_BLACK = new Color(0, 0, 0, 0);
private final int r, g, b, a; private final int r, g, b, a;

View File

@ -44,7 +44,7 @@ public class Terminal {
cell.fullChar = 0; cell.fullChar = 0;
cell.secondChar = 0; cell.secondChar = 0;
cell.halfWidth = false; cell.halfWidth = false;
cell.bgColor = Color.BLACK; cell.bgColor = Color.TRANS_BLACK;
cell.fgColor = Color.WHITE; cell.fgColor = Color.WHITE;
cells.add(cell); cells.add(cell);
} }