added colour parameter to string drawing functions
This commit is contained in:
parent
903e5246dc
commit
2dc18a01fb
|
@ -1,4 +1,5 @@
|
|||
import com.danitheskunk.skunkworks.*;
|
||||
import com.danitheskunk.skunkworks.gfx.Color;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
|
@ -26,8 +27,9 @@ public class Test {
|
|||
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16));
|
||||
var font = window.loadFontTileset("EGA8x14.png");
|
||||
var font2 = window.loadFontTTF("fonts\\LiberationSans-Regular.ttf", 16*8.f);
|
||||
var font3 = window.loadFontTTF("fonts\\LiberationSans-Regular.ttf", 16);
|
||||
var tex = window.loadTexture(img);
|
||||
var slice = window.loadNineSlice("demoassets\\9slice-1.png");
|
||||
var slice = window.loadNineSlice("demoassets\\9slice-2.png");
|
||||
//window.setDebug(true);
|
||||
|
||||
while(!window.shouldClose()) {
|
||||
|
@ -50,11 +52,12 @@ public class Test {
|
|||
true
|
||||
);
|
||||
|
||||
renderContext.drawString(new Vec2i(100, 100), "hello world mew", font);
|
||||
renderContext.drawString(new Vec2i(710, 140), "hello world mew", font2);
|
||||
|
||||
|
||||
renderContext.drawNineSlice(slice, new Recti(100, 100, 200, 50));
|
||||
renderContext.drawNineSlice(slice, new Recti(100, 100, 75, 23));
|
||||
//renderContext.drawString(new Vec2i(118, 117), "Meow", font3, new Color(0,0,0));
|
||||
renderContext.drawString(new Vec2i(122, 105), "Meow", font, new Color(0,0,0));
|
||||
window.renderFinish(renderContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,14 @@ class RenderContext extends BaseRenderContext implements IRenderContext {
|
|||
private final int texCoordIndex;
|
||||
private final int texOffsetIndex;
|
||||
private final int texSizeIndex;
|
||||
private final int tintIndex;
|
||||
|
||||
public RenderContext(TextureAtlas atlas, int texCoordIndex, int texOffsetIndex, int texSizeIndex) {
|
||||
public RenderContext(TextureAtlas atlas, int texCoordIndex, int texOffsetIndex, int texSizeIndex, int tintIndex) {
|
||||
this.atlas = atlas;
|
||||
this.texCoordIndex = texCoordIndex;
|
||||
this.texOffsetIndex = texOffsetIndex;
|
||||
this.texSizeIndex = texSizeIndex;
|
||||
this.tintIndex = tintIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -154,11 +156,12 @@ class RenderContext extends BaseRenderContext implements IRenderContext {
|
|||
tbr = Vec2i.sub(tex.getTexArea().getBottomRight(), topleft);
|
||||
}
|
||||
|
||||
glColor4f(
|
||||
glUniform3f(
|
||||
tintIndex,
|
||||
color.getR() / 255.0f,
|
||||
color.getG() / 255.0f,
|
||||
color.getB() / 255.0f,
|
||||
color.getA() / 255.0f
|
||||
color.getB() / 255.0f
|
||||
//color.getA() / 255.0f
|
||||
);
|
||||
|
||||
glUniform2i(texOffsetIndex, topleft.getX(), topleft.getY());
|
||||
|
|
|
@ -56,7 +56,8 @@ public class Window extends BaseWindow {
|
|||
textureAtlas,
|
||||
program.getAttribLocation("texCoord"),
|
||||
program.getUniformLocation("texOffset"),
|
||||
program.getUniformLocation("texSize")
|
||||
program.getUniformLocation("texSize"),
|
||||
program.getUniformLocation("tint")
|
||||
);
|
||||
glProgramUniform2f(program.program, program.getUniformLocation("windowSize"), size.getX(), size.getY());
|
||||
|
||||
|
@ -159,11 +160,12 @@ public class Window extends BaseWindow {
|
|||
layout(binding = 0) uniform sampler2D tex;
|
||||
layout(location = 3) uniform ivec2 texOffset;
|
||||
layout(location = 4) uniform ivec2 texSize;
|
||||
layout(location = 5) uniform vec3 tint;
|
||||
out vec4 color;
|
||||
void main() {
|
||||
//color = vec4(vec2(texCoord).x/1000.f, 0.2f, 0.7f, 1.0f);
|
||||
//color = texture(tex, texCoord);
|
||||
color = texelFetch(tex, ivec2(mod(texCoord, texSize)) + texOffset, 0);
|
||||
color = texelFetch(tex, ivec2(mod(texCoord, texSize)) + texOffset, 0) * vec4(tint, 1.0f);
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@ import java.nio.IntBuffer;
|
|||
|
||||
abstract public class BaseRenderContext implements IRenderContext {
|
||||
public void drawString(Vec2i pos, String string, IFont font) {
|
||||
drawString(pos, string, font, Color.WHITE);
|
||||
}
|
||||
|
||||
public void drawString(Vec2i pos, String string, IFont font, Color color) {
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
IntBuffer buf;
|
||||
|
@ -22,7 +26,7 @@ abstract public class BaseRenderContext implements IRenderContext {
|
|||
int ch = buf.get(i);
|
||||
var tex = font.getTexture(ch);
|
||||
var off = font.getOffset(ch);
|
||||
drawTextureRectangle(new Recti(Vec2i.add(new Vec2i(x, y), off), tex.getSize()), tex, true);
|
||||
drawTextureRectangle(new Recti(Vec2i.add(new Vec2i(x, y), off), tex.getSize()), tex, color, true);
|
||||
x += font.getXAdvance(ch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ public interface IRenderContext {
|
|||
void drawNineSlice(NineSlice slice, Recti rect); //todo: add rounding mode
|
||||
void drawRectangle(Recti rect, Color color);
|
||||
void drawString(Vec2i pos, String string, IFont font);
|
||||
void drawString(Vec2i pos, String string, IFont font, Color color);
|
||||
void drawTexture(Vec2i pos, ITexture texture);
|
||||
void drawTexture(Vec2i pos, ITexture texture, Color color);
|
||||
void drawTextureRectangle(Recti rect, ITexture texture, boolean repeat);
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 148 B After Width: | Height: | Size: 162 B |
Binary file not shown.
After Width: | Height: | Size: 228 B |
Loading…
Reference in New Issue