From 57a2eff6c19cfd5fd8c9b10a2b3beca6617b4d5d Mon Sep 17 00:00:00 2001 From: Henri Vasserman Date: Sun, 11 Apr 2021 12:17:53 +0300 Subject: [PATCH] add more mac stuff --- .gitignore | 1 + CMakeLists.txt | 12 ++++++++++++ platform.h.in | 2 ++ xormod.c | 20 ++++++++++++-------- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 platform.h.in diff --git a/.gitignore b/.gitignore index 567609b..bbbf928 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c7ba0..fa000a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,18 @@ project(xormod C) find_package(SDL2) +if(APPLE) + set(DETECTED_ACCEL_PLATFORM "METAL") +else() + set(DETECTED_ACCEL_PLATFORM "OPENGL") +endif() + +set(ACCEL_PLATFORM ${DETECTED_ACCEL_PLATFORM} CACHE STRING "Acceleration") + +configure_file("platform.h.in" "config/platform.h") + +include_directories("${CMAKE_BINARY_DIR}/config") + add_executable(xormod "xormod.c" "font.c" diff --git a/platform.h.in b/platform.h.in new file mode 100644 index 0000000..069ec3a --- /dev/null +++ b/platform.h.in @@ -0,0 +1,2 @@ +#define ACCEL_PLATFORM SDL_WINDOW_${ACCEL_PLATFORM} +#define ACCEL_PLATFORM_STR "${ACCEL_PLATFORM}" diff --git a/xormod.c b/xormod.c index c892431..e0e8053 100644 --- a/xormod.c +++ b/xormod.c @@ -1,5 +1,6 @@ #include "font.h" #include "EGA8x8.h" +#include "platform.h" #include #include @@ -35,11 +36,12 @@ static Picture *Picture_new(SDL_Renderer *rend, p->y2 = y + h; p->w = w; p->h = h; - p->pixels = malloc(w * h * sizeof(uint32_t)); p->color = color; + int stride = (w + 7) / 8 * 8; + p->pixels = malloc(stride * h * sizeof(uint32_t)); p->surface = SDL_CreateRGBSurfaceWithFormatFrom( - p->pixels, w, h, 32, w * sizeof(uint32_t), + p->pixels, w, h, 32, stride * sizeof(uint32_t), SDL_PIXELFORMAT_RGBA32); Picture_render(p, rend); @@ -84,7 +86,7 @@ int main() { SDL_Window *window = SDL_CreateWindow("xormod", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, - SDL_WINDOW_OPENGL /*SDL_WINDOW_FULLSCREEN */); + ACCEL_PLATFORM | SDL_WINDOW_FULLSCREEN); if (window == NULL) { fprintf(stderr, "Can't open window: %s\n", SDL_GetError()); return -1; @@ -93,7 +95,7 @@ int main() { SDL_GetWindowSize(window, &w, &h); SDL_Renderer *rend = SDL_CreateRenderer(window, -1, - /*SDL_RENDERER_PRESENTVSYNC | */SDL_RENDERER_ACCELERATED); + SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); SDL_Texture *font = load_font(rend); @@ -114,16 +116,16 @@ int main() { break; } if (keys[SDL_SCANCODE_LEFT]) { - off.x -= 5; + off.x -= 16; } if (keys[SDL_SCANCODE_RIGHT]) { - off.x += 5; + off.x += 16; } if (keys[SDL_SCANCODE_UP]) { - off.y -= 5; + off.y -= 16; } if (keys[SDL_SCANCODE_DOWN]) { - off.y += 5; + off.y += 16; } struct int2 mouse; @@ -195,6 +197,8 @@ int main() { // q[i], p->x1, p->x2, p->y1, p->y2, p); // draw_text(rend, font, buf, len, RC(2+i, 1), 255, 255, 255); //} + + //draw_text(rend, font, ACCEL_PLATFORM_STR, sizeof(ACCEL_PLATFORM_STR), RC(1,1), 255, 255, 255); SDL_RenderPresent(rend);