feat: font
This commit is contained in:
parent
aa24eb14d2
commit
dc533860a9
|
@ -79,3 +79,6 @@ target_compile_options(clfontft2 PUBLIC
|
|||
${PNG_CFLAGS_OTHER}
|
||||
${FREETYPE_CFLAGS_OTHER}
|
||||
${SDL2_CFLAGS_OTHER})
|
||||
|
||||
add_executable (stt stt.c)
|
||||
target_link_libraries (stt PRIVATE m)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,48 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate
|
||||
// implementation
|
||||
#include "stb_truetype.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint8_t *bitmap;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("stt <font> [char] [height]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w, h, i, j, c = (argc > 2 ? atoi(argv[2]) : 'a'),
|
||||
s = (argc > 3 ? atoi(argv[3]) : 20);
|
||||
|
||||
long size;
|
||||
uint8_t *font_buffer;
|
||||
|
||||
FILE *font_file = fopen(argv[1], "rb");
|
||||
fseek(font_file, 0, SEEK_END);
|
||||
size = ftell(font_file); /* how long is the file ? */
|
||||
fseek(font_file, 0, SEEK_SET); /* reset */
|
||||
|
||||
font_buffer = (uint8_t *)malloc(size);
|
||||
|
||||
fread(font_buffer, size, 1, font_file);
|
||||
fclose(font_file);
|
||||
|
||||
stbtt_fontinfo info;
|
||||
if (!stbtt_InitFont(&info, font_buffer, 0)) {
|
||||
printf("failed\n");
|
||||
}
|
||||
bitmap = stbtt_GetCodepointBitmap(
|
||||
&info, 0, stbtt_ScaleForPixelHeight(&info, s), c, &w, &h, 0, 0);
|
||||
|
||||
for (j = 0; j < h; ++j) {
|
||||
for (i = 0; i < w; ++i)
|
||||
putchar(" .:ioVM@"[bitmap[j * w + i] >> 5]);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
free(font_buffer);
|
||||
return 0;
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
#include <stdlib.h> /**< rand */
|
||||
|
||||
#include "sww/app.h"
|
||||
#include "sww/fps_helper.h"
|
||||
#include "sww/rate_helper.h"
|
||||
#include "sww/renderer.h"
|
||||
#include "sww/texture.h"
|
||||
#include "sww/util.h"
|
||||
|
@ -109,11 +111,14 @@ float Sample(float x, float y, int method) {
|
|||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 1) {
|
||||
printf("[I] Please provide a font file path!");
|
||||
if (argc < 2) {
|
||||
printf("[I] Please provide a font file path!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
swwFpsHelper fps;
|
||||
swwRateHelper rh;
|
||||
|
||||
swwWindowCallback callback = {OnKey, OnButton, OnScroll};
|
||||
swwApp_Initialize();
|
||||
|
||||
|
@ -209,14 +214,23 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
free(font_buffer);
|
||||
free(bitmap);
|
||||
swwRenderer_ClearBlack(ud.renderer);
|
||||
|
||||
swwRenderer_EnablePerfMonitor(ud.renderer, 1);
|
||||
swwFpsHelper_Construct(&fps, 1.f);
|
||||
swwRateHelper_Construct(&rh, 30.f);
|
||||
while (!swwApp_ShouldExit()) {
|
||||
swwRenderer_DrawTexture(ud.renderer, tex, (Point2i){0, 0});
|
||||
swwRenderer_DrawRectangleTopLeft(ud.renderer, (Point2i){0, 0},
|
||||
swwRenderer_ClearBlack(ud.renderer);
|
||||
swwRenderer_DrawTexture(ud.renderer, tex, (Point2i){0, 128});
|
||||
swwRenderer_DrawRectangleTopLeft(ud.renderer, (Point2i){0, 128},
|
||||
(Sizei){512, 128}, kRed, 0);
|
||||
swwRenderer_Present(ud.renderer);
|
||||
swwApp_PollEvent();
|
||||
swwRateHelper_Sleep(&rh);
|
||||
|
||||
if (swwFpsHelper_Update(&fps, ud.renderer)) {
|
||||
printf("FPS: %s \r", swwFpsHelper_Get(&fps));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
swwTexture_Destroy(tex);
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
#include "sww/util.h"
|
||||
#include "sww/window.h"
|
||||
|
||||
#define W 500
|
||||
#define H 500
|
||||
|
||||
typedef struct {
|
||||
int w;
|
||||
int h;
|
||||
|
@ -60,13 +57,14 @@ typedef struct {
|
|||
} EyeGround;
|
||||
|
||||
int main() {
|
||||
int w, h;
|
||||
const uint32_t win_w = 512, win_h = 512;
|
||||
uint32_t w, h;
|
||||
int cw, ch;
|
||||
swwWindowCallback callback = {OnKey, OnButton, OnScroll};
|
||||
swwFpsHelper fps;
|
||||
swwApp_Initialize();
|
||||
|
||||
swwWindow *window = swwWindow_Create("SWW Texture", 500, 500);
|
||||
swwWindow *window = swwWindow_Create("SWW Texture", win_w, win_h);
|
||||
swwWindow_GetSize(window, &w, &h);
|
||||
UserData ud = {w, h, 1, NULL};
|
||||
ud.renderer = swwRenderer_CreateAttachWindow(window, kSoftwareRenderer);
|
||||
|
@ -74,8 +72,8 @@ int main() {
|
|||
|
||||
swwWindow_SetCallback(window, &callback);
|
||||
|
||||
int ww2 = (w - W) / 2;
|
||||
int hh2 = (h - H) / 2;
|
||||
int ww2 = (w - win_w) / 2;
|
||||
int hh2 = (h - win_h) / 2;
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue