72 lines
2.2 KiB
C
72 lines
2.2 KiB
C
//
|
|
// Created by rov on 12/27/25.
|
|
//
|
|
|
|
#include "bitmap.h"
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include "window.h"
|
|
|
|
bool Bitmap_Init(Bitmap_t* bitmap) {
|
|
SDL_Renderer* renderer = Window_GetRenderer();
|
|
|
|
SDL_Surface* tibiaSurface = Bitmap_LoadFromFile("TIBIA.BMP");
|
|
if (!tibiaSurface) {
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load TIBIA.BMP", NULL);
|
|
return false;
|
|
}
|
|
|
|
bitmap->tibiaTexture = SDL_CreateTextureFromSurface(renderer, tibiaSurface);
|
|
if (bitmap->tibiaTexture == NULL) {
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't create tibia texture", NULL);
|
|
return false;
|
|
}
|
|
|
|
SDL_DestroySurface(tibiaSurface);
|
|
|
|
SDL_Surface* marbleSurface = Bitmap_LoadFromFile("MARBLE.BMP");
|
|
if (!marbleSurface) {
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load MARBLE.BMP", NULL);
|
|
return false;
|
|
}
|
|
|
|
bitmap->marbleTexture = SDL_CreateTextureFromSurface(renderer, marbleSurface);
|
|
if (bitmap->marbleTexture == NULL) {
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't create marble texture", NULL);
|
|
return false;
|
|
}
|
|
|
|
SDL_DestroySurface(marbleSurface);
|
|
|
|
// TODO: Note: here, on the original client, it created a offscreen buffer of 36x36 pixels.
|
|
|
|
return true;
|
|
}
|
|
|
|
void Bitmap_Destroy(const Bitmap_t* bitmap) {
|
|
SDL_DestroyTexture(bitmap->tibiaTexture);
|
|
SDL_DestroyTexture(bitmap->marbleTexture);
|
|
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_Destroy: surfaces destroyed.");
|
|
}
|
|
|
|
SDL_Surface* Bitmap_LoadFromFile(const char* filename) {
|
|
SDL_IOStream* stream = SDL_IOFromFile(filename, "rb");
|
|
if (!stream) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_LoadFromFile: couldn't open file: %s", filename);
|
|
return NULL;
|
|
}
|
|
|
|
return SDL_LoadBMP_IO(stream, true);
|
|
}
|
|
|
|
SDL_Surface* Bitmap_LoadFromMemory(const void* buffer, const size_t size) {
|
|
SDL_IOStream* stream = SDL_IOFromConstMem(buffer, size);
|
|
if (!stream) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_LoadFromMemory: couldn't read from memory.");
|
|
return NULL;
|
|
}
|
|
|
|
return SDL_LoadBMP_IO(stream, true);
|
|
}
|