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/
*.swp

View File

@ -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"

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 "EGA8x8.h"
#include "platform.h"
#include <stdio.h>
#include <SDL.h>
@ -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);