fix for c++20 on linux

This commit is contained in:
Sven Balzer 2025-02-25 12:56:10 +01:00
parent 85d653db29
commit c70a9a245b
14 changed files with 8001 additions and 8220 deletions

View File

@ -18,6 +18,10 @@ find_program(SLANGC
PATHS /opt/shader-slang-bin/bin
)
# stb_image
add_library(stb_image STATIC libs/stb/stb_image.c)
target_include_directories(stb_image INTERFACE libs/stb)
function(add_shader name)
set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/assets/shader/${name}.slang)
set(OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/assets/shader/${name}.h)
@ -46,6 +50,7 @@ add_executable(mikemon
target_link_libraries(mikemon
PRIVATE
SDL3::SDL3
stb_image
)
add_dependencies(mikemon
basic_vertex_shader

2
libs/stb/stb_image.c Normal file
View File

@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

7988
libs/stb/stb_image.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

View File

@ -1,25 +0,0 @@
#include "create_window.h"
//create Window
void* create_window(LRESULT (*WindowProc)(HWND, UINT, WPARAM, LPARAM)) {
WNDCLASSEXA window_class_struct = {};
window_class_struct.cbSize = sizeof(WNDCLASSEXW);
window_class_struct.style = CS_CLASSDC | CS_HREDRAW | CS_VREDRAW;
window_class_struct.lpfnWndProc = WindowProc;
window_class_struct.cbClsExtra = 0;
window_class_struct.cbWndExtra = 0;
window_class_struct.hInstance = GetModuleHandle(NULL);
window_class_struct.hIcon = 0;
window_class_struct.hCursor = LoadCursor(NULL, IDC_ARROW);
window_class_struct.hbrBackground = 0;
window_class_struct.lpszMenuName = 0;
window_class_struct.lpszClassName = "DX_WINDOW_CLASS";
window_class_struct.hIconSm = 0;
ATOM window_class = RegisterClassExA(&window_class_struct);
if (!window_class)
return 0;
return CreateWindowExA(0, "DX_WINDOW_CLASS", "Pokemon", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(NULL), 0);
}

View File

@ -1,3 +0,0 @@
#pragma once
#include <Windows.h>
void* create_window(LRESULT(*WindowProc)(HWND, UINT, WPARAM, LPARAM));

View File

@ -1,174 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "load_tga_file.h"
#include "m_string.h"
#include "log.h"
#include "load_entire_file.h"
#define print_value(v) _Generic((v), \
int8_t: printf("%hhd", v), \
int16_t: printf("%hd", v), \
int32_t: printf("%d", v), \
int64_t: printf("%lld", v), \
long: printf("%lld", v), \
\
uint8_t: printf("%hhu", v), \
uint16_t: printf("%hu", v), \
uint32_t: printf("%u", v), \
uint64_t: printf("%llu", v), \
unsigned long: printf("%llu", v) \
)
bool _expect_read(String& file, String expected_value, const char* path, const char* error_msg) {
if (file.length < expected_value.length)
return false;
if (!(String{ expected_value.length, file.data } == expected_value)) {
log_error("'%s' %s expected '%.*s' got '%.*s'\n", path, error_msg, expected_value.length, expected_value.data, expected_value.length, file.data);
return false;
}
advance(file, expected_value.length);
return true;
}
template<typename T>
bool _expect_read(String& file, T expected_value, const char* path, const char* error_msg) {
if (file.length < sizeof(T))
return false;
if (*(T*)file.data != expected_value) {
printf("'%s' %s expected '", path, error_msg);
print_value(expected_value);
printf("' got '");
print_value(*(T*)file.data);
printf("'\n");
return false;
}
advance(file, sizeof(T));
return true;
}
template<typename T, typename S>
bool _expect(T value, S expected_value, const char* path, const char* error_msg) {
if (value != expected_value) {
printf("'%s' %s expected '", path, error_msg);
print_value(expected_value);
printf("' got '");
print_value(value);
printf("'\n");
return false;
}
return true;
}
#define expect_read(expected_value, error_msg) if(!_expect_read(file, expected_value, path, error_msg)) return{0, 0};
#define expect(value, expected_value, error_msg) if(!_expect(value, expected_value, path, error_msg)) return{0, 0};
#pragma pack(1)
struct TGA_Color_Map_Info {
uint16_t index;
uint16_t length;
uint8_t size;
};
#pragma pack(1)
struct TGA_Image_Specification {
uint16_t x_origin;
uint16_t y_origin;
uint16_t width;
uint16_t height;
uint8_t bits_per_pixel;
uint8_t image_descriptor;
};
void swap(uint32_t& a, uint32_t& b) {
uint32_t h;
h = a;
a = b;
b = h;
}
Image_Info load_tga_file(const char* path) {
auto file = load_entire_file(path);
auto start_file = file;
if (!file.length) {
log_error("'%s' failed to load", path);
return{ 0, 0, 0 };
}
auto id_length = read<uint8_t>(file);
auto color_map_type = read<uint8_t>(file);
expect(color_map_type, 0, "wrong color map type");
auto image_type = read<uint8_t>(file);
//expect(image_type, 10, "wrong image type");
if (image_type != 10 && image_type != 11) {
log_error("wrong image type, not monochrome or not rgb");
return{ 0, 0 };
}
auto color_map_info = read<TGA_Color_Map_Info >(file);
expect(color_map_info.size, 0, "no existing color map");
auto image_specification = read<TGA_Image_Specification>(file);
expect(image_specification.bits_per_pixel, 32, "not 32 bitsperpixel");
auto descriptor_mask = 0x30;
auto image_origin = image_specification.image_descriptor & descriptor_mask;
if (image_origin != 0 && image_origin != 32) {
log_error("wrong image origin");
return{ 0, 0 };
}
//TODO: y-achse flippen, weil microsoft, spaeter beide faelle implementieren
advance(file, id_length);
uint32_t* start_pixel = (uint32_t*)malloc(image_specification.width * image_specification.height * 4);
uint32_t* pixel = start_pixel;
if (!start_pixel) {
log_error("'%s' malloc failed", path);
return { 0, 0 };
}
auto needed_pixel = image_specification.height * image_specification.width;
for (; needed_pixel;) {
auto type_and_repetition_count = read<uint8_t>(file);
auto repetition_count = type_and_repetition_count & 0x7F;
if ((type_and_repetition_count & 0x80)) {
auto pixel_value = read<uint32_t>(file);
for (; repetition_count + 1; repetition_count--) {
*pixel = pixel_value;
pixel++;
needed_pixel--;
}
}
else {
for (; repetition_count + 1; repetition_count--) {
auto pixel_value = read<uint32_t>(file);
*pixel = pixel_value;
pixel++;
needed_pixel--;
}
}
}
if (image_origin != 32) {
for (int y = 0; y < (image_specification.height / 2); y++) {
for (int x = 0; x < image_specification.width; x++)
swap(start_pixel[y * image_specification.width + x], start_pixel[image_specification.width * (image_specification.height - y - 1) + x]);
}
}
return { image_specification.width, image_specification.height, start_pixel };
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <stdint.h>
struct Image_Info {
int64_t width;
int64_t height;
uint32_t* pixel;
};
Image_Info load_tga_file(const char* path);

View File

@ -1,6 +1,5 @@
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <SDL3/SDL.h>
#include "defer.h"
@ -8,7 +7,6 @@
#include "m_string.h"
#include "math_graphics.h"
#include "load_entire_file.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "glyphs.h"
#include "../assets/shader/basic_vertex_shader.h"
@ -43,7 +41,6 @@ int16 window_width;
int16 window_height;
bool Running = true;
//
#define view_width 17
#define view_height 13

View File

@ -74,11 +74,11 @@ constexpr float lerp(float a, float b, float t) {
return (1.0f - t) * a + t * b;
}
float ilerp(float a, float b, float v) {
inline float ilerp(float a, float b, float v) {
return (v - a) / (b - a);
}
float remap(float in_a, float in_b, float out_a, float out_b, float v) {
inline float remap(float in_a, float in_b, float out_a, float out_b, float v) {
float t = ilerp(in_a, in_b, v);
return lerp(out_a, out_b, t);
}
@ -282,12 +282,12 @@ inline V2 lerp(V2 a, V2 b, V2 t) {
}
//
V2 ilerp(V2 a, V2 b, V2 v) {
inline V2 ilerp(V2 a, V2 b, V2 v) {
return (v - a) / (b - a);
}
//
V2 remap(V2 in_a, V2 in_b, V2 out_a, V2 out_b, V2 v) {
inline V2 remap(V2 in_a, V2 in_b, V2 out_a, V2 out_b, V2 v) {
V2 t = ilerp(in_a, in_b, v);
return lerp(out_a, out_b, t);
}

File diff suppressed because it is too large Load Diff