fixing windows dll issues

This commit is contained in:
kbz_8
2023-12-08 23:33:26 +01:00
parent 5dcc2045d6
commit d16af1c4a8
43 changed files with 121 additions and 110 deletions

View File

@@ -28,7 +28,7 @@
namespace mlx::core
{
class MLX_API Application
class Application
{
public:
Application();

View File

@@ -15,6 +15,7 @@
#include "application.h"
#include <renderer/core/render_core.h>
#include <filesystem>
#include <mlx.h>
extern "C"
{
@@ -31,29 +32,29 @@ extern "C"
if(app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "Tout a pété");
init = true;
return app;
return static_cast<void*>(app);
}
void* mlx_new_window(mlx::core::Application* mlx, int w, int h, const char* title)
void* mlx_new_window(void* mlx, int w, int h, const char* title)
{
return mlx->newGraphicsSuport(w, h, title);
return static_cast<mlx::core::Application*>(mlx)->newGraphicsSuport(w, h, title);
}
int mlx_loop_hook(mlx::core::Application* mlx, int (*f)(void*), void* param)
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param)
{
mlx->loopHook(f, param);
static_cast<mlx::core::Application*>(mlx)->loopHook(f, param);
return 0;
}
int mlx_loop(mlx::core::Application* mlx)
int mlx_loop(void* mlx)
{
mlx->run();
static_cast<mlx::core::Application*>(mlx)->run();
return 0;
}
int mlx_loop_end(mlx::core::Application* mlx)
int mlx_loop_end(void* mlx)
{
mlx->loopEnd();
static_cast<mlx::core::Application*>(mlx)->loopEnd();
return 0;
}
@@ -67,57 +68,57 @@ extern "C"
return SDL_ShowCursor(SDL_DISABLE);
}
int mlx_mouse_move(mlx::core::Application* mlx, void* win, int x, int y)
int mlx_mouse_move(void* mlx, void* win, int x, int y)
{
mlx->mouseMove(win, x, y);
static_cast<mlx::core::Application*>(mlx)->mouseMove(win, x, y);
return 0;
}
int mlx_mouse_get_pos(mlx::core::Application* mlx, int* x, int* y)
int mlx_mouse_get_pos(void* mlx, int* x, int* y)
{
mlx->getMousePos(x, y);
static_cast<mlx::core::Application*>(mlx)->getMousePos(x, y);
return 0;
}
int mlx_on_event(mlx::core::Application* mlx, void* win, int event, int (*funct_ptr)(int, void*), void* param)
int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*funct_ptr)(int, void*), void* param)
{
mlx->onEvent(win, event, funct_ptr, param);
static_cast<mlx::core::Application*>(mlx)->onEvent(win, static_cast<int>(event), funct_ptr, param);
return 0;
}
void* mlx_new_image(mlx::core::Application* mlx, int width, int height)
void* mlx_new_image(void* mlx, int width, int height)
{
return mlx->newTexture(width, height);
return static_cast<mlx::core::Application*>(mlx)->newTexture(width, height);
}
int mlx_get_image_pixel(mlx::core::Application* mlx, void* img, int x, int y)
int mlx_get_image_pixel(void* mlx, void* img, int x, int y)
{
return mlx->getTexturePixel(img, x, y);
return static_cast<mlx::core::Application*>(mlx)->getTexturePixel(img, x, y);
}
void mlx_set_image_pixel(mlx::core::Application* mlx, void* img, int x, int y, int color)
void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = (color & 0x000000FF);
color_bits[3] = (color & 0xFF000000) >> 24;
mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
static_cast<mlx::core::Application*>(mlx)->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
}
int mlx_put_image_to_window(mlx::core::Application* mlx, void* win, void* img, int x, int y)
int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
{
mlx->texturePut(win, img, x, y);
static_cast<mlx::core::Application*>(mlx)->texturePut(win, img, x, y);
return 0;
}
int mlx_destroy_image(mlx::core::Application* mlx, void* img)
int mlx_destroy_image(void* mlx, void* img)
{
mlx->destroyTexture(img);
static_cast<mlx::core::Application*>(mlx)->destroyTexture(img);
return 0;
}
void* mlx_png_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".png")
@@ -125,10 +126,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "PNG loader : not a png file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
void* mlx_jpg_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
@@ -136,10 +137,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "JPG loader : not a jpg file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
void* mlx_bmp_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".bmp" && file.extension() != ".dib")
@@ -147,32 +148,32 @@ extern "C"
mlx::core::error::report(e_kind::error, "BMP loader : not a bmp file '%s'", filename);
return nullptr;
}
return mlx->newStbTexture(filename, width, height);
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
}
int mlx_pixel_put(mlx::core::Application* mlx, void* win, int x, int y, int color)
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
mlx->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
static_cast<mlx::core::Application*>(mlx)->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
return 0;
}
int mlx_string_put(mlx::core::Application* mlx, void* win, int x, int y, int color, char* str)
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
mlx->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
return 0;
}
void mlx_set_font(mlx::core::Application* mlx, void* win, char* filepath)
void mlx_set_font(void* mlx, void* win, char* filepath)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
@@ -180,10 +181,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, 16.f);
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, 16.f);
}
void mlx_set_font_scale(mlx::core::Application* mlx, void* win, char* filepath, float scale)
void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
@@ -191,31 +192,31 @@ extern "C"
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, scale);
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, scale);
}
int mlx_clear_window(mlx::core::Application* mlx, void* win)
int mlx_clear_window(void* mlx, void* win)
{
mlx->clearGraphicsSupport(win);
static_cast<mlx::core::Application*>(mlx)->clearGraphicsSupport(win);
return 0;
}
int mlx_destroy_window(mlx::core::Application* mlx, void* win)
int mlx_destroy_window(void* mlx, void* win)
{
mlx->destroyGraphicsSupport(win);
static_cast<mlx::core::Application*>(mlx)->destroyGraphicsSupport(win);
return 0;
}
int mlx_destroy_display(mlx::core::Application* mlx)
int mlx_destroy_display(void* mlx)
{
delete mlx;
delete static_cast<mlx::core::Application*>(mlx);
mlx::Render_Core::get().destroy();
return 0;
}
int mlx_get_screens_size(mlx::core::Application* mlx, int* w, int* h)
int mlx_get_screens_size(void* mlx, int* w, int* h)
{
mlx->getScreenSize(w, h);
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
return 0;
}
}
}

View File

@@ -26,7 +26,7 @@ enum class e_kind
namespace mlx::core::error
{
void MLX_API report(e_kind kind, std::string msg, ...);
void report(e_kind kind, std::string msg, ...);
}
#endif // __MLX_ERRORS__

View File

@@ -30,7 +30,7 @@
namespace mlx
{
class MLX_API GraphicsSupport : public non_copyable
class GraphicsSupport : public non_copyable
{
public:
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);

View File

@@ -19,7 +19,7 @@
namespace mlx
{
class MLX_API MemManager : public Singleton<MemManager>
class MemManager : public Singleton<MemManager>
{
friend class Singleton<MemManager>;

View File

@@ -41,19 +41,18 @@
#warning "This compiler is not fully supported"
#endif
#if defined(_WIN32) || defined(_WIN64)
#define MLX_EXPORT __declspec(dllexport)
#define MLX_IMPORT __declspec(dllexport)
#if defined(_WIN32) || defined(__CYGWIN__)
#define MLX_PLAT_WINDOWS
#elif defined(__linux__)
#define MLX_PLAT_LINUX
#elif defined(__APPLE__) && defined(__MACH__)
#define MLX_PLAT_MACOS
#elif defined(unix) || defined(__unix__) || defined(__unix)
#define MLX_PLAT_UNIX
#else
#define MLX_EXPORT
#define MLX_IMPORT
#error "Unknown environment!"
#endif
#ifdef MLX_BUILD
#define MLX_API MLX_EXPORT
#else
#define MLX_API MLX_IMPORT
#endif
// Checking common assumptions
#include <climits>