-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.c
79 lines (61 loc) · 1.5 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Create Window
//
#include <SDL.h>
#include <SDL_events.h>
#include <SDL_ttf.h>
#ifdef PLATFORM_EMCC
#include <emscripten.h>
#endif
#include <stdio.h>
int _isQuit = 0;
SDL_Surface *screen;
TTF_Font *font;
SDL_Texture *text_tex;
SDL_Window* window;
SDL_Renderer* renderer;
void main_loop(void*args) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
_isQuit = 1;
}
}
SDL_RenderClear(renderer);
SDL_Rect text_dest = {.x = 50, .y = 175, .w = 0, .h = 0};
SDL_QueryTexture(text_tex,
NULL, NULL, &text_dest.w, &text_dest.h);
SDL_RenderCopy(renderer, text_tex, NULL, &text_dest);
SDL_RenderPresent(renderer);
}
typedef struct {
int dummy;
} Context;
Context ctx;
int main( int argc, char* args[] )
{
printf("main\r\n");
// SDL_Init(SDL_INIT_EVERYTHING);
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
SDL_CreateWindowAndRenderer(600, 400, 0, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
SDL_RenderClear(renderer);
//
font = TTF_OpenFont("./assets/Roboto-Bold.ttf", 30);
SDL_Color fg = {0,0,0,255};
SDL_Surface *text_surface = TTF_RenderText_Blended(font, "test test !!", fg);
text_tex = SDL_CreateTextureFromSurface(renderer, text_surface);
SDL_FreeSurface(text_surface);
//SDL_RenderPresent(renderer);
#ifdef PLATFORM_EMCC
emscripten_set_main_loop_arg(main_loop, &ctx, 60, 1);
#else
do {
main_loop(&ctx);
} while(_isQuit == 0);
#endif
printf("main 3 \r\n");
return 0;
}