add more mac stuff
parent
1daf59732f
commit
57a2eff6c1
|
@ -1 +1,2 @@
|
||||||
build/
|
build/
|
||||||
|
*.swp
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#define ACCEL_PLATFORM SDL_WINDOW_${ACCEL_PLATFORM}
|
||||||
|
#define ACCEL_PLATFORM_STR "${ACCEL_PLATFORM}"
|
20
xormod.c
20
xormod.c
|
@ -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;
|
||||||
|
@ -195,6 +197,8 @@ int main() {
|
||||||
// q[i], p->x1, p->x2, p->y1, p->y2, p);
|
// 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, 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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue