render marble.bmp on the background

This commit is contained in:
Rodrigo Verdiani 2025-12-27 02:25:29 -03:00
parent 17b3ae0bee
commit fb0f846f83
9 changed files with 76 additions and 22 deletions

View File

@ -20,7 +20,7 @@ add_executable(tibia main.c
map.h
bitmap.c
bitmap.h
Objects.c
Objects.h)
objects.c
objects.h)
target_link_libraries(tibia SDL3::SDL3)

2
app.c
View File

@ -35,7 +35,7 @@ void App_Init(App_t *app) {
void App_Run(App_t *app) {
while (app->isRunning) {
Input_Poll(app);
Render_Frame();
Render_Frame(app);
}
}

2
app.h
View File

@ -5,7 +5,7 @@
#include "bitmap.h"
#include "config.h"
#include "Objects.h"
#include "objects.h"
#include "map.h"
#include "system.h"

View File

@ -4,31 +4,48 @@
#include "bitmap.h"
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_messagebox.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL.h>
#include "window.h"
bool Bitmap_Init(Bitmap_t* bitmap) {
bitmap->tibiaSurface = Bitmap_LoadFromFile("TIBIA.BMP");
if (!bitmap->tibiaSurface) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load tibia.bmp", NULL);
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->marbleSurface = Bitmap_LoadFromFile("MARBLE.BMP");
if (!bitmap->marbleSurface) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load marble.bmp", NULL);
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_DestroySurface(bitmap->tibiaSurface);
SDL_DestroySurface(bitmap->marbleSurface);
SDL_DestroyTexture(bitmap->tibiaTexture);
SDL_DestroyTexture(bitmap->marbleTexture);
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_Destroy: surfaces destroyed.");
}

View File

@ -4,11 +4,11 @@
#ifndef TIBIA_BITMAP_H
#define TIBIA_BITMAP_H
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL.h>
typedef struct Bitmap {
SDL_Surface* tibiaSurface;
SDL_Surface* marbleSurface;
SDL_Texture* tibiaTexture;
SDL_Texture* marbleTexture;
} Bitmap_t ;
bool Bitmap_Init(Bitmap_t* bitmap);

View File

@ -2,7 +2,7 @@
// Created by rov on 12/27/25.
//
#include "Objects.h"
#include "objects.h"
#include <stdlib.h>
#include <string.h>

View File

@ -5,10 +5,41 @@
#include "render.h"
#include "window.h"
void Render_Frame() {
void Render_Frame(const App_t *app) {
SDL_Renderer *renderer = Window_GetRenderer();
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
Render_MainWindowBackground(app);
SDL_RenderPresent(renderer);
}
void Render_MainWindowBackground(const App_t *app) {
SDL_Renderer *renderer = Window_GetRenderer();
if (app->bitmap.marbleTexture == NULL) {
SDL_SetRenderDrawColor(renderer, 64, 64, 64, 255);
SDL_RenderClear(renderer);
return;
}
const int TILE_SIZE = 128;
// Calculate how many tiles we need to cover the screen
const int tilesX = app->metrics.screenWidth / TILE_SIZE + 1;
const int tilesY = app->metrics.screenHeight / TILE_SIZE + 1;
for (int y = 0; y < tilesY; y++) {
for (int x = 0; x < tilesX; x++) {
SDL_FRect destRect = {
(float) (x * TILE_SIZE),
(float) (y * TILE_SIZE),
(float) TILE_SIZE,
(float) TILE_SIZE
};
SDL_RenderTexture(renderer, app->bitmap.marbleTexture, NULL, &destRect);
}
}
}

View File

@ -4,7 +4,13 @@
#ifndef TIBIA_RENDER_H
#define TIBIA_RENDER_H
#include <SDL3/SDL_render.h>
void Render_Frame();
#include "app.h"
void Render_Frame(const App_t* app);
void Render_MainWindowBackground(const App_t* app);
void Render_DrawWindowFrame(SDL_Renderer* renderer, int x, int y, int w, int h);
#endif //TIBIA_RENDER_H