add bold font
This commit is contained in:
parent
5a2f965295
commit
28c720f882
8 changed files with 4528 additions and 27 deletions
BIN
engine/data/font/bold.png
Normal file
BIN
engine/data/font/bold.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
|
@ -27,6 +27,7 @@ GSDECL GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* hei
|
|||
GSDECL GSBool GSGLTextureLoadFileEx(GSGL gl, GLuint* texture, int* width, int* height, const char* filename, int expand);
|
||||
GSDECL GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix);
|
||||
GSDECL GSBool GSGLTextureTryEx(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix, int expand);
|
||||
GSDECL void GSGLTextBold(GSGL gl, GSBool bold);
|
||||
GSDECL void GSGLTextEx(GSGL gl, GSNumber x, GSNumber y, const char* text, GSNumber sx, GSNumber sy);
|
||||
GSDECL void GSGLText(GSGL gl, GSNumber x, GSNumber y, const char* text);
|
||||
GSDECL double GSGLTextWidth(GSGL gl, const char* text);
|
||||
|
|
|
|||
|
|
@ -105,17 +105,27 @@ struct _GSGL {
|
|||
GLdouble shadow_projection[16];
|
||||
GLdouble shadow_old_projection[16];
|
||||
GLdouble shadow_old_modelview[16];
|
||||
|
||||
GSBool bold;
|
||||
};
|
||||
|
||||
struct _GSClient {
|
||||
GSEngine engine;
|
||||
|
||||
GSGL gl;
|
||||
GLuint font;
|
||||
int font_width;
|
||||
int font_height;
|
||||
int glyph_width;
|
||||
int glyph_height;
|
||||
GSGL gl;
|
||||
|
||||
GLuint font_normal;
|
||||
int font_normal_width;
|
||||
int font_normal_height;
|
||||
int glyph_normal_width;
|
||||
int glyph_normal_height;
|
||||
|
||||
GLuint font_bold;
|
||||
int font_bold_width;
|
||||
int font_bold_height;
|
||||
int glyph_bold_width;
|
||||
int glyph_bold_height;
|
||||
|
||||
GSVector3 look_at;
|
||||
GSVector3 camera;
|
||||
GSVector4 light0;
|
||||
|
|
@ -181,6 +191,7 @@ struct _GSEngine {
|
|||
int width;
|
||||
int height;
|
||||
GSNumber tps;
|
||||
GSNumber tps_sampled;
|
||||
};
|
||||
|
||||
struct _GSFile {
|
||||
|
|
|
|||
4420
engine/resource/font/7x14B.bdf
Normal file
4420
engine/resource/font/7x14B.bdf
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -9,6 +9,24 @@
|
|||
|
||||
GSClient GSClientCreate(GSEngine engine) {
|
||||
GSClient client = malloc(sizeof(*client));
|
||||
void* ptr[] = {
|
||||
"game:/font/normal", /**/
|
||||
"base:/font/normal", /**/
|
||||
&client->font_normal, /**/
|
||||
&client->glyph_normal_width, /**/
|
||||
&client->glyph_normal_height, /**/
|
||||
&client->font_normal_width, /**/
|
||||
&client->font_normal_height, /**/
|
||||
/**/
|
||||
"game:/font/bold", /**/
|
||||
"base:/font/bold", /**/
|
||||
&client->font_bold, /**/
|
||||
&client->glyph_bold_width, /**/
|
||||
&client->glyph_bold_height, /**/
|
||||
&client->font_bold_width, /**/
|
||||
&client->font_bold_height /**/
|
||||
};
|
||||
int i;
|
||||
|
||||
memset(client, 0, sizeof(*client));
|
||||
|
||||
|
|
@ -33,16 +51,22 @@ GSClient GSClientCreate(GSEngine engine) {
|
|||
|
||||
client->skybox = GSSkyBoxTry(client, "default");
|
||||
|
||||
if(GSGLTextureTryEx(client->gl, &client->font, &client->glyph_width, &client->glyph_height, "game:/font", 0)) {
|
||||
} else if(GSGLTextureTryEx(client->gl, &client->font, &client->glyph_width, &client->glyph_height, "base:/font", 0)) {
|
||||
} else {
|
||||
client->font = 0;
|
||||
}
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
client->font_width = GSMathClosestPOT(client->glyph_width);
|
||||
client->font_height = GSMathClosestPOT(client->glyph_height);
|
||||
client->glyph_width /= 16;
|
||||
client->glyph_height /= 16;
|
||||
for(i = 0; i < sizeof(ptr) / sizeof(ptr[0]); i += 7) {
|
||||
if(GSGLTextureTryEx(client->gl, ptr[i + 2], ptr[i + 3], ptr[i + 4], ptr[i], 0)) {
|
||||
} else if(GSGLTextureTryEx(client->gl, ptr[i + 2], ptr[i + 3], ptr[i + 4], ptr[i + 1], 0)) {
|
||||
} else {
|
||||
*((GLuint*)ptr[i + 2]) = 0;
|
||||
}
|
||||
|
||||
if(*((GLuint*)ptr[i + 2]) > 0) {
|
||||
*((int*)ptr[i + 5]) = GSMathClosestPOT(*((int*)ptr[i + 3]));
|
||||
*((int*)ptr[i + 6]) = GSMathClosestPOT(*((int*)ptr[i + 4]));
|
||||
*((int*)ptr[i + 3]) /= 16;
|
||||
*((int*)ptr[i + 4]) /= 16;
|
||||
}
|
||||
}
|
||||
|
||||
GSLog(GSLogInfo, "Created client");
|
||||
|
||||
|
|
@ -50,7 +74,8 @@ GSClient GSClientCreate(GSEngine engine) {
|
|||
}
|
||||
|
||||
void GSClientDestroy(GSClient client) {
|
||||
if(client->font != 0) GSGLTextureDelete(client->gl, client->font);
|
||||
if(client->font_normal != 0) GSGLTextureDelete(client->gl, client->font_normal);
|
||||
if(client->font_bold != 0) GSGLTextureDelete(client->gl, client->font_bold);
|
||||
|
||||
GSGLDestroy(client->gl);
|
||||
|
||||
|
|
@ -70,14 +95,17 @@ void GSClientStep(GSClient client) {
|
|||
char buf[512];
|
||||
char buf2[512];
|
||||
GSVersion ver;
|
||||
GSVector4 white = {1, 1, 1, 1};
|
||||
GSVector4 half = {0, 0, 0, 0.5};
|
||||
GSVector4 white = {1, 1, 1, 1};
|
||||
GSVector4 yellow = {1, 1, 0, 1};
|
||||
GSVector4 half = {0, 0, 0, 0.5};
|
||||
GSVector2 sq[4];
|
||||
|
||||
GSGLClear(client->gl);
|
||||
GSGLCameraSetup(client->gl);
|
||||
GSGLSetLight(client->gl);
|
||||
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
if(GSGLShadowBeforeMapping(client->gl)) {
|
||||
scene(client);
|
||||
GSGLShadowAfterMapping(client->gl);
|
||||
|
|
@ -89,9 +117,29 @@ void GSClientStep(GSClient client) {
|
|||
scene(client);
|
||||
GSGLShadowEnd(client->gl);
|
||||
|
||||
sprintf(buf, "%.1f FPS", client->engine->tps_sampled);
|
||||
|
||||
tw = GSGLTextWidth(client->gl, buf);
|
||||
th = GSGLTextHeight(client->gl, buf);
|
||||
|
||||
sq[0][0] = client->engine->width - tw, sq[0][1] = 0;
|
||||
sq[1][0] = client->engine->width - tw, sq[1][1] = th;
|
||||
sq[2][0] = client->engine->width, sq[2][1] = th;
|
||||
sq[3][0] = client->engine->width, sq[3][1] = 0;
|
||||
|
||||
GSGLSetColor(client->gl, half);
|
||||
GSGLBegin2D(client->gl);
|
||||
GSGLPolygon2D(client->gl, 4, sq, NULL);
|
||||
GSGLEnd2D(client->gl);
|
||||
|
||||
GSGLSetColor(client->gl, yellow);
|
||||
GSGLTextBold(client->gl, 1);
|
||||
GSGLText(client->gl, client->engine->width - tw, 0, buf);
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
GSVersionGet(&ver);
|
||||
|
||||
sprintf(buf, "GearSrc Engine %s", ver.string);
|
||||
sprintf(buf, "Engine version %s", ver.string);
|
||||
|
||||
tw = GSGLTextWidth(client->gl, buf);
|
||||
th = GSGLTextHeight(client->gl, buf);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ void GSEngineLoop(GSEngine engine) {
|
|||
long t = 0;
|
||||
int wait_actually = 0;
|
||||
GSNumber tps = 50;
|
||||
GSNumber tick = 1;
|
||||
int f = 5;
|
||||
long wait = 1000 / tps;
|
||||
|
||||
if(engine->param->sleep == NULL || engine->param->get_tick == NULL) {
|
||||
|
|
@ -127,7 +129,8 @@ void GSEngineLoop(GSEngine engine) {
|
|||
wait_actually = 1;
|
||||
}
|
||||
|
||||
engine->tps = tps;
|
||||
engine->tps = tps;
|
||||
engine->tps_sampled = tps;
|
||||
|
||||
while(1) {
|
||||
if(engine->client != NULL) GSClientStep(engine->client);
|
||||
|
|
@ -145,6 +148,20 @@ void GSEngineLoop(GSEngine engine) {
|
|||
|
||||
engine->tps = 1000.0 / (engine->param->get_tick() - t);
|
||||
|
||||
if(f > 0) {
|
||||
engine->tps_sampled = engine->tps;
|
||||
|
||||
f--;
|
||||
}
|
||||
|
||||
tick += 1.0 / engine->tps;
|
||||
if(tick >= 1) {
|
||||
engine->tps_sampled += engine->tps;
|
||||
engine->tps_sampled /= 2;
|
||||
|
||||
tick = tick - 1;
|
||||
}
|
||||
|
||||
t = engine->param->get_tick();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,18 +70,22 @@ GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const c
|
|||
return GSGLTextureTryEx(gl, texture, width, height, prefix, 1);
|
||||
}
|
||||
|
||||
void GSGLTextBold(GSGL gl, GSBool bold) {
|
||||
gl->bold = bold;
|
||||
}
|
||||
|
||||
void GSGLTextEx(GSGL gl, GSNumber x, GSNumber y, const char* text, GSNumber sx, GSNumber sy) {
|
||||
GSNumber px = x;
|
||||
GSNumber py = y;
|
||||
int i;
|
||||
GSClient client = gl->engine->client;
|
||||
GSNumber gw = client->glyph_width * sx;
|
||||
GSNumber gh = client->glyph_height * sy;
|
||||
GSNumber sw = (GSNumber)client->glyph_width / client->font_width;
|
||||
GSNumber sh = (GSNumber)client->glyph_height / client->font_height;
|
||||
GSNumber gw = (gl->bold ? client->glyph_bold_width : client->glyph_normal_width) * sx;
|
||||
GSNumber gh = (gl->bold ? client->glyph_bold_height : client->glyph_normal_height) * sy;
|
||||
GSNumber sw = (GSNumber)(gl->bold ? client->glyph_bold_width : client->glyph_normal_width) / (gl->bold ? client->font_bold_width : client->font_normal_width);
|
||||
GSNumber sh = (GSNumber)(gl->bold ? client->glyph_bold_height : client->glyph_normal_height) / (gl->bold ? client->font_bold_height : client->font_normal_height);
|
||||
|
||||
GSGLBegin2D(gl);
|
||||
GSGLTextureSet(gl, client->font);
|
||||
GSGLTextureSet(gl, gl->bold ? client->font_bold : client->font_normal);
|
||||
|
||||
for(i = 0; text[i] != 0; i++) {
|
||||
GSVector2 v[4];
|
||||
|
|
@ -116,11 +120,11 @@ void GSGLText(GSGL gl, GSNumber x, GSNumber y, const char* text) {
|
|||
}
|
||||
|
||||
double GSGLTextWidth(GSGL gl, const char* text) {
|
||||
return gl->engine->client->glyph_width * strlen(text);
|
||||
return (gl->bold ? gl->engine->client->glyph_bold_width : gl->engine->client->glyph_normal_width) * strlen(text);
|
||||
}
|
||||
|
||||
double GSGLTextHeight(GSGL gl, const char* text) {
|
||||
return gl->engine->client->glyph_height;
|
||||
return (gl->bold ? gl->engine->client->glyph_bold_height : gl->engine->client->glyph_normal_height);
|
||||
}
|
||||
|
||||
void GSGLTexturePrepareEx(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height, int expand) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue