mirror of https://github.com/aap/librw.git
some font rendering
This commit is contained in:
parent
c53d29b1cf
commit
b7f643a632
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
Binary file not shown.
After Width: | Height: | Size: 128 KiB |
|
@ -0,0 +1,162 @@
|
|||
#include <rw.h>
|
||||
#include <skeleton.h>
|
||||
|
||||
using namespace rw;
|
||||
|
||||
struct Font
|
||||
{
|
||||
Texture *tex;
|
||||
int32 glyphwidth, glyphheight;
|
||||
int32 numglyphs;
|
||||
};
|
||||
Font vga = { nil, 8, 16, 256 };
|
||||
Font bios = { nil, 8, 8, 256 };
|
||||
Font *curfont = &bios;
|
||||
|
||||
#define NUMCHARS 100
|
||||
uint16 indices[NUMCHARS*6];
|
||||
RWDEVICE::Im2DVertex vertices[NUMCHARS*4];
|
||||
int32 curVert;
|
||||
int32 curIndex;
|
||||
|
||||
void
|
||||
printScreen(const char *s, float32 x, float32 y)
|
||||
{
|
||||
char c;
|
||||
Camera *cam;
|
||||
RWDEVICE::Im2DVertex *vert;
|
||||
uint16 *ix;
|
||||
curVert = 0;
|
||||
curIndex = 0;
|
||||
float32 u, v, du, dv;
|
||||
|
||||
cam = (Camera*)engine->currentCamera;
|
||||
vert = &vertices[curVert];
|
||||
ix = &indices[curIndex];
|
||||
du = curfont->glyphwidth/(float32)curfont->tex->raster->width;
|
||||
dv = curfont->glyphheight/(float32)curfont->tex->raster->height;
|
||||
while(c = *s){
|
||||
if(c >= curfont->numglyphs)
|
||||
c = 0;
|
||||
u = (c % 16)*curfont->glyphwidth / (float32)curfont->tex->raster->width;
|
||||
v = (c / 16)*curfont->glyphheight / (float32)curfont->tex->raster->height;
|
||||
|
||||
vert->setScreenX(x);
|
||||
vert->setScreenY(y);
|
||||
vert->setScreenZ(rw::GetNearZ());
|
||||
vert->setCameraZ(cam->nearPlane);
|
||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
||||
vert->setColor(255, 255, 255, 255);
|
||||
vert->setU(u);
|
||||
vert->setV(v);
|
||||
vert++;
|
||||
|
||||
vert->setScreenX(x+curfont->glyphwidth);
|
||||
vert->setScreenY(y);
|
||||
vert->setScreenZ(rw::GetNearZ());
|
||||
vert->setCameraZ(cam->nearPlane);
|
||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
||||
vert->setColor(255, 255, 255, 255);
|
||||
vert->setU(u+du);
|
||||
vert->setV(v);
|
||||
vert++;
|
||||
|
||||
vert->setScreenX(x);
|
||||
vert->setScreenY(y+curfont->glyphheight);
|
||||
vert->setScreenZ(rw::GetNearZ());
|
||||
vert->setCameraZ(cam->nearPlane);
|
||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
||||
vert->setColor(255, 255, 255, 255);
|
||||
vert->setU(u);
|
||||
vert->setV(v+dv);
|
||||
vert++;
|
||||
|
||||
vert->setScreenX(x+curfont->glyphwidth);
|
||||
vert->setScreenY(y+curfont->glyphheight);
|
||||
vert->setScreenZ(rw::GetNearZ());
|
||||
vert->setCameraZ(cam->nearPlane);
|
||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
||||
vert->setColor(255, 255, 255, 255);
|
||||
vert->setU(u+du);
|
||||
vert->setV(v+dv);
|
||||
vert++;
|
||||
|
||||
*ix++ = curVert;
|
||||
*ix++ = curVert+1;
|
||||
*ix++ = curVert+2;
|
||||
*ix++ = curVert+2;
|
||||
*ix++ = curVert+1;
|
||||
*ix++ = curVert+3;
|
||||
|
||||
curVert += 4;
|
||||
curIndex += 6;
|
||||
x += curfont->glyphwidth+1;
|
||||
|
||||
s++;
|
||||
}
|
||||
engine->imtexture = curfont->tex;
|
||||
rw::engine->device.im2DRenderIndexedPrimitive(rw::PRIMTYPETRILIST,
|
||||
vertices, curVert, indices, curIndex);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
initFont(void)
|
||||
{
|
||||
vga.tex = Texture::read("Bm437_IBM_VGA8", "");
|
||||
bios.tex = Texture::read("Bm437_IBM_BIOS", "");
|
||||
}
|
||||
|
||||
/*
|
||||
#define NUMGLYPHS 256
|
||||
#define GLYPHWIDTH 8
|
||||
#define GLYPHHEIGHT 16
|
||||
|
||||
|
||||
void
|
||||
convertFont(void)
|
||||
{
|
||||
FILE *f;
|
||||
Image *img;
|
||||
uint8 data[NUMGLYPHS*GLYPHHEIGHT];
|
||||
int32 i, x, y;
|
||||
uint8 *px, *line, *glyph;
|
||||
// f = fopen("font0.bin", "rb");
|
||||
f = fopen("Bm437_IBM_VGA8.FON", "rb");
|
||||
// f = fopen("Bm437_IBM_BIOS.FON", "rb");
|
||||
if(f == nil)
|
||||
return;
|
||||
fseek(f, 0x65A, 0);
|
||||
fread(data, 1, NUMGLYPHS*GLYPHHEIGHT, f);
|
||||
fclose(f);
|
||||
|
||||
img = Image::create(16*GLYPHWIDTH, NUMGLYPHS/16*GLYPHHEIGHT, 32);
|
||||
img->allocate();
|
||||
for(i = 0; i < NUMGLYPHS; i++){
|
||||
glyph = &data[i*GLYPHHEIGHT];
|
||||
x = (i % 16)*GLYPHWIDTH;
|
||||
y = (i / 16)*GLYPHHEIGHT;
|
||||
line = &img->pixels[x*4 + y*img->stride];
|
||||
for(y = 0; y < GLYPHHEIGHT; y++){
|
||||
px = line;
|
||||
for(x = 0; x < 8; x++){
|
||||
if(*glyph & 1<<(8-x)){
|
||||
*px++ = 255;
|
||||
*px++ = 255;
|
||||
*px++ = 255;
|
||||
*px++ = 255;
|
||||
}else{
|
||||
*px++ = 0;
|
||||
*px++ = 0;
|
||||
*px++ = 0;
|
||||
*px++ = 0;
|
||||
}
|
||||
}
|
||||
glyph++;
|
||||
line += img->stride;
|
||||
}
|
||||
}
|
||||
// writeTGA(img, "Bm437_IBM_BIOS.tga");
|
||||
writeTGA(img, "Bm437_IBM_VGA8.tga");
|
||||
}
|
||||
*/
|
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
|
@ -14,6 +14,8 @@ rw::Texture *tex;
|
|||
rw::EngineStartParams engineStartParams;
|
||||
|
||||
void tlTest(rw::Clump *clump);
|
||||
void initFont(void);
|
||||
void printScreen(const char *s, float x, float y);
|
||||
|
||||
void
|
||||
Init(void)
|
||||
|
@ -158,6 +160,8 @@ InitRW(void)
|
|||
if(!sk::InitRW())
|
||||
return false;
|
||||
|
||||
initFont();
|
||||
|
||||
tex = rw::Texture::read("maze", nil);
|
||||
|
||||
char *filename = "teapot.dff";
|
||||
|
@ -270,6 +274,7 @@ Draw(float timeDelta)
|
|||
Scene.clump->render();
|
||||
im2dtest();
|
||||
// tlTest(Scene.clump);
|
||||
printScreen("Hello, World!", 10, 10);
|
||||
|
||||
camera->m_rwcam->endUpdate();
|
||||
camera->m_rwcam->showRaster();
|
||||
|
|
Loading…
Reference in New Issue