update font
This commit is contained in:
parent
2608502217
commit
5a2f965295
12 changed files with 2066 additions and 2701 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 4.8 KiB |
|
|
@ -17,7 +17,7 @@ GSDECL unsigned int GSFileSize(GSFile file);
|
|||
GSDECL void GSFileClose(GSFile file);
|
||||
|
||||
/* getline.c */
|
||||
GSDECL int GSFileGetLine(char** lineptr, int* n, FILE* fp);
|
||||
GSDECL int GSFileGetLine(GSFile file, char** lineptr, int* n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,15 +16,19 @@ extern "C" {
|
|||
GSDECL GSBool GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs);
|
||||
|
||||
/* gl_texture.c */
|
||||
GSDECL void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height);
|
||||
GSDECL void GSGLTextureLoad(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height); /* you probably don't want this. use GSGLTexturePrepare */
|
||||
GSDECL void GSGLTextureSet(GSGL gl, GLuint texture);
|
||||
GSDECL void GSGLTextureDelete(GSGL gl, GLuint texture);
|
||||
|
||||
/* gl_common.c */
|
||||
GSDECL void GSGLTexturePrepareEx(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height, int expand);
|
||||
GSDECL void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height);
|
||||
GSDECL GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename);
|
||||
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 void GSGLTextEx(GSGL gl, double x, double y, double sx, double sy, const char* text);
|
||||
GSDECL void GSGLText(GSGL gl, double x, double y, const char* text);
|
||||
GSDECL GSBool GSGLTextureTryEx(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix, int expand);
|
||||
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);
|
||||
GSDECL double GSGLTextHeight(GSGL gl, const char* text);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ GSDECL void GSMathNormal3x3(GSVector3 r, GSVector3 v0, GSVector3 v1, GSVector3 v
|
|||
GSDECL void GSMathNormal3x4(GSVector3 r, GSVector3 v0, GSVector3 v1, GSVector3 v2, GSVector3 v3);
|
||||
GSDECL void GSMathInvert4x4(GSMatrix4x4 out, GSMatrix4x4 in);
|
||||
GSDECL GSNumber GSMathCot(GSNumber x);
|
||||
GSDECL GSNumber GSMathClosestPOT(GSNumber x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ struct _GSClient {
|
|||
GLuint font;
|
||||
int font_width;
|
||||
int font_height;
|
||||
int glyph_width;
|
||||
int glyph_height;
|
||||
GSVector3 look_at;
|
||||
GSVector3 camera;
|
||||
GSVector4 light0;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -33,12 +33,17 @@ GSClient GSClientCreate(GSEngine engine) {
|
|||
|
||||
client->skybox = GSSkyBoxTry(client, "default");
|
||||
|
||||
if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "game:/font")) {
|
||||
} else if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "base:/font")) {
|
||||
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;
|
||||
}
|
||||
|
||||
client->font_width = GSMathClosestPOT(client->glyph_width);
|
||||
client->font_height = GSMathClosestPOT(client->glyph_height);
|
||||
client->glyph_width /= 16;
|
||||
client->glyph_height /= 16;
|
||||
|
||||
GSLog(GSLogInfo, "Created client");
|
||||
|
||||
return client;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
#define GETLINE_MINSIZE 16
|
||||
|
||||
int GSFileGetLine(char** lineptr, int* n, FILE* fp) {
|
||||
int ch;
|
||||
int GSFileGetLine(GSFile file, char** lineptr, int* n) {
|
||||
char ch;
|
||||
int i = 0;
|
||||
char free_on_err = 0;
|
||||
char* p;
|
||||
|
||||
if(lineptr == NULL || n == NULL || fp == NULL) {
|
||||
if(lineptr == NULL || n == NULL || file == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if(*lineptr == NULL) {
|
||||
|
|
@ -21,7 +21,7 @@ int GSFileGetLine(char** lineptr, int* n, FILE* fp) {
|
|||
}
|
||||
|
||||
for(i = 0;; i++) {
|
||||
ch = fgetc(fp);
|
||||
int r = GSFileRead(file, &ch, 1);
|
||||
while(i >= (*n) - 2) {
|
||||
*n *= 2;
|
||||
p = realloc(*lineptr, sizeof(char) * (*n));
|
||||
|
|
@ -32,7 +32,7 @@ int GSFileGetLine(char** lineptr, int* n, FILE* fp) {
|
|||
}
|
||||
*lineptr = p;
|
||||
}
|
||||
if(ch == EOF) {
|
||||
if(r < 1) {
|
||||
if(i == 0) {
|
||||
if(free_on_err)
|
||||
free(*lineptr);
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include <GearSrc/String.h>
|
||||
#include <GearSrc/File.h>
|
||||
#include <GearSrc/Math.h>
|
||||
|
||||
#include <stb_image.h>
|
||||
|
||||
GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) {
|
||||
GSBool GSGLTextureLoadFileEx(GSGL gl, GLuint* texture, int* width, int* height, const char* filename, int expand) {
|
||||
GSFile f = GSFileOpen(gl->engine, filename);
|
||||
unsigned char* data;
|
||||
unsigned char* rgba;
|
||||
|
|
@ -24,7 +25,7 @@ GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, co
|
|||
if((rgba = stbi_load_from_memory(data, sz, &w, &h, &ch, 4)) == NULL) {
|
||||
st = GSFalse;
|
||||
} else {
|
||||
GSGLTexturePrepare(gl, texture, rgba, w, h);
|
||||
GSGLTexturePrepareEx(gl, texture, rgba, w, h, expand);
|
||||
|
||||
free(rgba);
|
||||
}
|
||||
|
|
@ -37,18 +38,22 @@ GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, co
|
|||
return st;
|
||||
}
|
||||
|
||||
GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) {
|
||||
GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) {
|
||||
return GSGLTextureLoadFileEx(gl, texture, width, height, filename, 1);
|
||||
}
|
||||
|
||||
GSBool GSGLTextureTryEx(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix, int expand) {
|
||||
char* png = GSStringConcat(prefix, ".png");
|
||||
char* bmp = GSStringConcat(prefix, ".bmp");
|
||||
char* jpg = GSStringConcat(prefix, ".jpg");
|
||||
char* jpeg = GSStringConcat(prefix, ".jpeg");
|
||||
GSBool st = GSTrue;
|
||||
|
||||
if(GSGLTextureLoadFile(gl, texture, width, height, prefix)) {
|
||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, png)) {
|
||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, bmp)) {
|
||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpg)) {
|
||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpeg)) {
|
||||
if(GSGLTextureLoadFileEx(gl, texture, width, height, prefix, expand)) {
|
||||
} else if(GSGLTextureLoadFileEx(gl, texture, width, height, png, expand)) {
|
||||
} else if(GSGLTextureLoadFileEx(gl, texture, width, height, bmp, expand)) {
|
||||
} else if(GSGLTextureLoadFileEx(gl, texture, width, height, jpg, expand)) {
|
||||
} else if(GSGLTextureLoadFileEx(gl, texture, width, height, jpeg, expand)) {
|
||||
} else {
|
||||
st = GSFalse;
|
||||
}
|
||||
|
|
@ -61,37 +66,41 @@ GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const c
|
|||
return st;
|
||||
}
|
||||
|
||||
void GSGLTextEx(GSGL gl, double x, double y, double sx, double sy, const char* text) {
|
||||
double px = x;
|
||||
double py = y;
|
||||
int i;
|
||||
double gw = gl->engine->client->font_width / 16 * sx;
|
||||
double gh = gl->engine->client->font_height / 16 * sy;
|
||||
GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) {
|
||||
return GSGLTextureTryEx(gl, texture, width, height, prefix, 1);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
GSGLBegin2D(gl);
|
||||
GSGLTextureSet(gl, gl->engine->client->font);
|
||||
GSGLTextureSet(gl, client->font);
|
||||
|
||||
for(i = 0; text[i] != 0; i++) {
|
||||
GSVector2 v[4];
|
||||
GSVector2 t[4];
|
||||
double gx = text[i] % 16;
|
||||
double gy = text[i] / 16;
|
||||
GSNumber gx = text[i] % 16;
|
||||
GSNumber gy = text[i] / 16;
|
||||
|
||||
gx = gx / 16;
|
||||
gy = gy / 16;
|
||||
gx = gx * sw;
|
||||
gy = gy * sh;
|
||||
|
||||
v[0][0] = px, v[0][1] = py;
|
||||
|
||||
v[1][0] = px, v[1][1] = py + gh;
|
||||
|
||||
v[2][0] = px + gw, v[2][1] = py + gh;
|
||||
|
||||
v[3][0] = px + gw, v[3][1] = py;
|
||||
|
||||
t[0][0] = gx, t[0][1] = gy;
|
||||
t[1][0] = gx, t[1][1] = gy + 1.0 / 16;
|
||||
t[2][0] = gx + 1.0 / 16, t[2][1] = gy + 1.0 / 16;
|
||||
t[3][0] = gx + 1.0 / 16, t[3][1] = gy;
|
||||
t[1][0] = gx, t[1][1] = gy + sh;
|
||||
t[2][0] = gx + sw, t[2][1] = gy + sh;
|
||||
t[3][0] = gx + sw, t[3][1] = gy;
|
||||
|
||||
GSGLPolygon2D(gl, 4, v, t);
|
||||
|
||||
|
|
@ -102,14 +111,60 @@ void GSGLTextEx(GSGL gl, double x, double y, double sx, double sy, const char* t
|
|||
GSGLEnd2D(gl);
|
||||
}
|
||||
|
||||
void GSGLText(GSGL gl, double x, double y, const char* text) {
|
||||
GSGLTextEx(gl, x, y, 1, 1, text);
|
||||
void GSGLText(GSGL gl, GSNumber x, GSNumber y, const char* text) {
|
||||
GSGLTextEx(gl, x, y, text, 1, 1);
|
||||
}
|
||||
|
||||
double GSGLTextWidth(GSGL gl, const char* text) {
|
||||
return gl->engine->client->font_width / 16 * strlen(text);
|
||||
return gl->engine->client->glyph_width * strlen(text);
|
||||
}
|
||||
|
||||
double GSGLTextHeight(GSGL gl, const char* text) {
|
||||
return gl->engine->client->font_height / 16;
|
||||
return gl->engine->client->glyph_height;
|
||||
}
|
||||
|
||||
void GSGLTexturePrepareEx(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height, int expand) {
|
||||
int w, h;
|
||||
unsigned char* d;
|
||||
int i, y, x;
|
||||
GSNumber sx, sy;
|
||||
|
||||
w = GSMathClosestPOT(width);
|
||||
h = GSMathClosestPOT(height);
|
||||
|
||||
d = malloc(w * h * 4);
|
||||
|
||||
if(expand) {
|
||||
sx = (GSNumber)width / w;
|
||||
sy = (GSNumber)height / h;
|
||||
|
||||
for(y = 0; y < h; y++) {
|
||||
int fy = y * sy;
|
||||
for(x = 0; x < w; x++) {
|
||||
int fx = x * sx;
|
||||
unsigned char* fp = &rgba[(fy * width + fx) * 4];
|
||||
unsigned char* tp = &d[(y * w + x) * 4];
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
tp[i] = fp[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
memset(d, 0, w * h * 4);
|
||||
|
||||
for(y = 0; y < height; y++) {
|
||||
for(x = 0; x < width; x++) {
|
||||
for(i = 0; i < 4; i++) d[(y * w + x) * 4 + i] = rgba[(y * width + x) * 4 + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GSGLTextureLoad(gl, texture, d, w, h);
|
||||
|
||||
free(d);
|
||||
}
|
||||
|
||||
void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height) {
|
||||
GSGLTexturePrepareEx(gl, texture, rgba, width, height, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <GearSrc/GL.h>
|
||||
|
||||
void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height) {
|
||||
void GSGLTextureLoad(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height) {
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
|
||||
|
|
|
|||
|
|
@ -103,3 +103,11 @@ void GSMathInvert4x4(GSMatrix4x4 out, GSMatrix4x4 in) {
|
|||
for(i = 0; i < 16; i++)
|
||||
out[i] = inv[i] * det;
|
||||
}
|
||||
|
||||
GSNumber GSMathClosestPOT(GSNumber x) {
|
||||
GSNumber r = 2;
|
||||
|
||||
while(r < x) r *= 2;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ int main() {
|
|||
int p = 0;
|
||||
int y = 0;
|
||||
int w, h;
|
||||
GSFile file = GSFileOpen(NULL, "/dev/stdin");
|
||||
|
||||
while((linelen = GSFileGetLine(&line, &linesize, stdin)) != -1) {
|
||||
while((linelen = GSFileGetLine(file, &line, &linesize)) != -1) {
|
||||
linelen--;
|
||||
|
||||
line[linelen] = 0;
|
||||
|
|
@ -30,8 +31,9 @@ int main() {
|
|||
|
||||
if(font != NULL) free(font);
|
||||
|
||||
iw = w * 16;
|
||||
ih = h * 16;
|
||||
iw = w * 16;
|
||||
ih = h * 16;
|
||||
|
||||
font = malloc(iw * ih * 4);
|
||||
memset(font, 0, iw * ih * 4);
|
||||
} else if(CHECK("ENCODING ")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue