add more mac stuff

main
Henri Vasserman 2021-04-11 12:17:53 +03:00
parent 1daf59732f
commit 57a2eff6c1
4 changed files with 27 additions and 8 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build/ build/
*.swp

View File

@ -4,6 +4,18 @@ project(xormod C)
find_package(SDL2) 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 add_executable(xormod
"xormod.c" "xormod.c"
"font.c" "font.c"

2
platform.h.in Normal file
View File

@ -0,0 +1,2 @@
#define ACCEL_PLATFORM SDL_WINDOW_${ACCEL_PLATFORM}
#define ACCEL_PLATFORM_STR "${ACCEL_PLATFORM}"

View File

@ -1,5 +1,6 @@
#include "font.h" #include "font.h"
#include "EGA8x8.h" #include "EGA8x8.h"
#include "platform.h"
#include <stdio.h> #include <stdio.h>
#include <SDL.h> #include <SDL.h>
@ -35,11 +36,12 @@ static Picture *Picture_new(SDL_Renderer *rend,
p->y2 = y + h; p->y2 = y + h;
p->w = w; p->w = w;
p->h = h; p->h = h;
p->pixels = malloc(w * h * sizeof(uint32_t));
p->color = color; p->color = color;
int stride = (w + 7) / 8 * 8;
p->pixels = malloc(stride * h * sizeof(uint32_t));
p->surface = SDL_CreateRGBSurfaceWithFormatFrom( 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); SDL_PIXELFORMAT_RGBA32);
Picture_render(p, rend); Picture_render(p, rend);
@ -84,7 +86,7 @@ int main() {
SDL_Window *window = SDL_CreateWindow("xormod", SDL_Window *window = SDL_CreateWindow("xormod",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h,
SDL_WINDOW_OPENGL /*SDL_WINDOW_FULLSCREEN */); ACCEL_PLATFORM | SDL_WINDOW_FULLSCREEN);
if (window == NULL) { if (window == NULL) {
fprintf(stderr, "Can't open window: %s\n", SDL_GetError()); fprintf(stderr, "Can't open window: %s\n", SDL_GetError());
return -1; return -1;
@ -93,7 +95,7 @@ int main() {
SDL_GetWindowSize(window, &w, &h); SDL_GetWindowSize(window, &w, &h);
SDL_Renderer *rend = SDL_CreateRenderer(window, -1, 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); SDL_Texture *font = load_font(rend);
@ -114,16 +116,16 @@ int main() {
break; break;
} }
if (keys[SDL_SCANCODE_LEFT]) { if (keys[SDL_SCANCODE_LEFT]) {
off.x -= 5; off.x -= 16;
} }
if (keys[SDL_SCANCODE_RIGHT]) { if (keys[SDL_SCANCODE_RIGHT]) {
off.x += 5; off.x += 16;
} }
if (keys[SDL_SCANCODE_UP]) { if (keys[SDL_SCANCODE_UP]) {
off.y -= 5; off.y -= 16;
} }
if (keys[SDL_SCANCODE_DOWN]) { if (keys[SDL_SCANCODE_DOWN]) {
off.y += 5; off.y += 16;
} }
struct int2 mouse; struct int2 mouse;
@ -196,6 +198,8 @@ int main() {
// draw_text(rend, font, buf, len, RC(2+i, 1), 255, 255, 255); // 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); SDL_RenderPresent(rend);
SDL_Event e; SDL_Event e;