diff options
author | chai <chaifix@163.com> | 2020-02-22 18:17:06 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-22 18:17:06 +0800 |
commit | 9c89460e136ed6c6c43704d9a3a15105e0f006b0 (patch) | |
tree | cd56f1dfc10650cfbfe7007ee3432ee32227edc3 /src/main.c | |
parent | d49f3d3f73709a9a7c0bce53aa13ed28a2bd27cb (diff) |
*wog
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 54 |
1 files changed, 20 insertions, 34 deletions
@@ -1,12 +1,10 @@ -#include <SDL2/SDL.h> #include <stdio.h> #include <windows.h> #include "math/math.h" #include "util/assert.h" #include "ssr.h" #include "example/example.h" - -SDL_Surface* suf; +#include "extern/wog.h" #define SCREEN_WIDTH 600 #define SCREEN_HEIGHT 480 @@ -20,7 +18,7 @@ F ondraw; /*macro这里需要绕一下弯*/ /*https://stackoverflow.com/questions/1489932/how-to-concatenate-twice-with-the-c-preprocessor-and-expand-a-macro-as-in-arg*/ #define SETEXAMPLEF(f, e) \ -f = f##e; +f = f##_##e; #define SETEXAMPLE(i) \ SETEXAMPLEF(onload, i)\ @@ -28,46 +26,35 @@ SETEXAMPLEF(ondraw, i)\ SETEXAMPLEF(onevent, i)\ SETEXAMPLEF(onupdate, i) -int main(int argc, char* argv[]) -{ - if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) - return 1; - SDL_Window* wnd = SDL_CreateWindow("Soft Shade Room", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); - SDL_Event e; - suf = SDL_GetWindowSurface(wnd); - /* ARGB format */ - ssr_assert(suf->format->BitsPerPixel == 32); - ssr_assert(suf->format->Rshift == 16); - ssr_assert(suf->format->Gshift == 8); - ssr_assert(suf->format->Bshift == 0); - +int main(int argc, char* argv[]) { + wog_Window* wnd = wog_createWindow("test", SCREEN_WIDTH, SCREEN_HEIGHT, 500, 500, 0); + wog_show(wnd); + wog_Surface* surface = wog_getsurface(wnd); // ARGB format /* init ssr */ ssr_Config config = { SCREEN_WIDTH, SCREEN_HEIGHT, 0, - suf->pixels + surface->buffer }; ssr_init(&config); - SETEXAMPLE(EXAMPLECUR); - onload(0); - /* main loop */ - uint prev = SDL_GetTicks(); + uint prev = wog_tick(); uint dt = 0; uint frame_count = 0; uint time_stamp = 0; + wog_Event e; while (1) { - while (SDL_PollEvent(&e)) { - if (e.type == SDL_QUIT) { + while (wog_pollEvent(wnd, &e)) { + if (e.type == WOG_ECLOSE) { goto quit; } else { onevent(&e); } } - - dt = SDL_GetTicks() - prev; + + dt = wog_tick() - prev; prev += dt; time_stamp += dt; ++frame_count; @@ -76,17 +63,16 @@ int main(int argc, char* argv[]) time_stamp -= 1000; frame_count = 0; } - + onupdate(&dt); ondraw(0); ssr_present(); - SDL_UpdateWindowSurface(wnd); - - /*Sleep(1);*/ /*reduce cpu using*/ + wog_updateSurface(wnd); + Sleep(1); /*reduce cpu using*/ } + + quit: + wog_destroyWindow(wnd); -quit: - SDL_Quit(); - - return 0; + return 1; } |