text
This commit is contained in:
parent
d07a84c7cf
commit
09763df314
7 changed files with 88 additions and 4 deletions
|
|
@ -13,7 +13,7 @@ file(GLOB SERVER_SRC server/*.c)
|
|||
file(GLOB CLIENT_SRC client/*.c)
|
||||
|
||||
add_executable(af_server ${SERVER_SRC})
|
||||
add_executable(af_client ${CLIENT_SRC})
|
||||
add_executable(af_client ${CLIENT_SRC} external/stb/stb_image.c)
|
||||
add_executable(af_dumpfont tools/af_dumpfont.c external/stb/stb_image_write.c)
|
||||
|
||||
target_include_directories(af_server PRIVATE include external/stb ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ void gl_init(void) {
|
|||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
gl_font_init();
|
||||
}
|
||||
|
||||
void gl_render(void) {
|
||||
|
|
|
|||
74
client/gl_font.c
Normal file
74
client/gl_font.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include <af_common.h>
|
||||
|
||||
#include <stb_image.h>
|
||||
|
||||
static GLuint font_atlas;
|
||||
static int font_width = 0, font_height = 0;
|
||||
|
||||
void gl_font_init(void) {
|
||||
unsigned int ch;
|
||||
unsigned char* data = stbi_load(DATAROOTDIR "/assaultfish/font.png", &font_width, &font_height, &ch, 4);
|
||||
|
||||
glGenTextures(1, &font_atlas);
|
||||
glBindTexture(GL_TEXTURE_2D, font_atlas);
|
||||
if(data != NULL) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, font_width, font_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
free(data);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void gl_font_text(const char* text, int x, int y, double scale) {
|
||||
int i;
|
||||
int gw = font_width / 16 * scale, gh = font_height / 16 * scale;
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, font_atlas);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, MwGetInteger(opengl, MwNwidth), MwGetInteger(opengl, MwNheight), 0, -1, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
for(i = 0; text[i] != 0; i++) {
|
||||
double bx = 1.0 / 16 * (text[i] % 16), by = 1.0 / 16 * (text[i] / 16);
|
||||
|
||||
glTexCoord2f(bx, by);
|
||||
glVertex2f(i * gw + x, y);
|
||||
glTexCoord2f(bx + 1.0 / 16, by);
|
||||
glVertex2f(i * gw + x + gw, y);
|
||||
glTexCoord2f(bx + 1.0 / 16, by + 1.0 / 16);
|
||||
glVertex2f(i * gw + x + gw, y + gh);
|
||||
glTexCoord2f(bx, by + 1.0 / 16);
|
||||
glVertex2f(i * gw + x, y + gh);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
int gl_font_width(const char* text) {
|
||||
return font_width / 16 * strlen(text);
|
||||
}
|
||||
|
||||
int gl_font_height(const char* text) {
|
||||
return font_height / 16;
|
||||
}
|
||||
|
|
@ -31,5 +31,5 @@ void gl_main_draw(void) {
|
|||
glPopMatrix();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
r += 1;
|
||||
r += 60.0 / (1000.0 / AF_WAIT_MS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ int main(int argc, char** argv) {
|
|||
MwLibraryInit();
|
||||
|
||||
root = MwVaCreateWidget(NULL, "root", NULL, 0, 0, 0, 0,
|
||||
MwNwaitMS, 15,
|
||||
MwNwaitMS, AF_WAIT_MS,
|
||||
MwNbitmapFont, 0,
|
||||
MwNmodernLook, 1,
|
||||
NULL);
|
||||
|
|
|
|||
2
external/libfishsoup
vendored
2
external/libfishsoup
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit c8b5c70a82c568f0f3696094395413b2979d3ff1
|
||||
Subproject commit 19a044c00adf6a839c30337be51c53399adc1f75
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <GL/glu.h>
|
||||
|
||||
#define AF_WAIT_MS 15
|
||||
|
||||
enum AF_SCENES {
|
||||
AF_SCENE_MAIN = 0
|
||||
};
|
||||
|
|
@ -34,6 +36,12 @@ void gl_init(void);
|
|||
void gl_render(void);
|
||||
void gl_resize(int width, int height);
|
||||
|
||||
/* gl_font.c */
|
||||
void gl_font_init(void);
|
||||
void gl_font_text(const char* text, int x, int y, double scale);
|
||||
int gl_font_width(const char* text);
|
||||
int gl_font_height(const char* text);
|
||||
|
||||
/* gl_main.c */
|
||||
void gl_main_init(void);
|
||||
void gl_main_draw(void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue