basic font rendering implemented, and alpha blending
This commit is contained in:
parent
3edbc36844
commit
07ced1f430
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
|
@ -7,9 +7,10 @@ public class Test {
|
||||||
var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png");
|
var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png");
|
||||||
var tex2 = window.loadTexture("C:\\art\\pixel stuff.png");
|
var tex2 = window.loadTexture("C:\\art\\pixel stuff.png");
|
||||||
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16));
|
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16));
|
||||||
|
var font = window.loadFontTileset("EGA8x14.png");
|
||||||
//img.drawImage(img2, Vec2i.ZERO);
|
//img.drawImage(img2, Vec2i.ZERO);
|
||||||
var tex = window.loadTexture(img);
|
var tex = window.loadTexture(img);
|
||||||
window.setDebug(true);
|
window.setDebug(false);
|
||||||
|
|
||||||
while(!window.shouldClose()) {
|
while(!window.shouldClose()) {
|
||||||
window.tick();
|
window.tick();
|
||||||
|
@ -27,6 +28,8 @@ public class Test {
|
||||||
new Recti(new Vec2i(400, 400), new Vec2i(16, 16)),
|
new Recti(new Vec2i(400, 400), new Vec2i(16, 16)),
|
||||||
tileset.get(0x30)
|
tileset.get(0x30)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
renderContext.drawString(new Vec2i(100, 100), "hello world mew", font);
|
||||||
window.renderFinish(renderContext);
|
window.renderFinish(renderContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
abstract class BaseRenderContext implements IRenderContext {
|
||||||
|
public void drawString(Vec2i pos, String string, IFont font) {
|
||||||
|
int x = pos.getX();
|
||||||
|
int y = pos.getY();
|
||||||
|
IntBuffer buf;
|
||||||
|
try {
|
||||||
|
buf = ByteBuffer.wrap(string.getBytes("UTF-32")).asIntBuffer();
|
||||||
|
} catch(UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < string.length(); ++i) {
|
||||||
|
int ch = buf.get(i);
|
||||||
|
var tex = font.getTexture(ch);
|
||||||
|
drawTextureRectangle(new Recti(new Vec2i(x, y), tex.getSize()), tex);
|
||||||
|
x += font.getCharWidth(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
class GLRenderContext implements IRenderContext{
|
class GLRenderContext extends BaseRenderContext implements IRenderContext{
|
||||||
private final GLTextureAtlas atlas;
|
private final GLTextureAtlas atlas;
|
||||||
|
|
||||||
public GLRenderContext(GLTextureAtlas atlas) {
|
public GLRenderContext(GLTextureAtlas atlas) {
|
||||||
|
|
|
@ -41,6 +41,8 @@ class GLWindow extends BaseWindow {
|
||||||
glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f);
|
glOrtho(0.0f, size.getX(), size.getY(), 0.0f, 0.0f, 1.0f);
|
||||||
glEnable(GL_COLOR);
|
glEnable(GL_COLOR);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
textureAtlas = new GLTextureAtlas();
|
textureAtlas = new GLTextureAtlas();
|
||||||
renderContext = new GLRenderContext(textureAtlas);
|
renderContext = new GLRenderContext(textureAtlas);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.danitheskunk.skunkworks;
|
||||||
|
|
||||||
public interface IRenderContext {
|
public interface IRenderContext {
|
||||||
void drawRectangle(Recti rect, Color color);
|
void drawRectangle(Recti rect, Color color);
|
||||||
|
void drawString(Vec2i pos, String string, IFont font);
|
||||||
void drawTextureRectangle(Recti rect, ITexture texture);
|
void drawTextureRectangle(Recti rect, ITexture texture);
|
||||||
void drawTextureRectangle(Recti rect, ITexture texture, Color color);
|
void drawTextureRectangle(Recti rect, ITexture texture, Color color);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue