render marble.bmp on the background
This commit is contained in:
parent
17b3ae0bee
commit
fb0f846f83
@ -20,7 +20,7 @@ add_executable(tibia main.c
|
|||||||
map.h
|
map.h
|
||||||
bitmap.c
|
bitmap.c
|
||||||
bitmap.h
|
bitmap.h
|
||||||
Objects.c
|
objects.c
|
||||||
Objects.h)
|
objects.h)
|
||||||
|
|
||||||
target_link_libraries(tibia SDL3::SDL3)
|
target_link_libraries(tibia SDL3::SDL3)
|
||||||
|
|||||||
2
app.c
2
app.c
@ -35,7 +35,7 @@ void App_Init(App_t *app) {
|
|||||||
void App_Run(App_t *app) {
|
void App_Run(App_t *app) {
|
||||||
while (app->isRunning) {
|
while (app->isRunning) {
|
||||||
Input_Poll(app);
|
Input_Poll(app);
|
||||||
Render_Frame();
|
Render_Frame(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
app.h
2
app.h
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Objects.h"
|
#include "objects.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
|||||||
39
bitmap.c
39
bitmap.c
@ -4,31 +4,48 @@
|
|||||||
|
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
|
|
||||||
#include <SDL3/SDL_log.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_messagebox.h>
|
#include "window.h"
|
||||||
#include <SDL3/SDL_render.h>
|
|
||||||
|
|
||||||
bool Bitmap_Init(Bitmap_t* bitmap) {
|
bool Bitmap_Init(Bitmap_t* bitmap) {
|
||||||
bitmap->tibiaSurface = Bitmap_LoadFromFile("TIBIA.BMP");
|
SDL_Renderer* renderer = Window_GetRenderer();
|
||||||
if (!bitmap->tibiaSurface) {
|
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load tibia.bmp", NULL);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap->marbleSurface = Bitmap_LoadFromFile("MARBLE.BMP");
|
bitmap->tibiaTexture = SDL_CreateTextureFromSurface(renderer, tibiaSurface);
|
||||||
if (!bitmap->marbleSurface) {
|
if (bitmap->tibiaTexture == NULL) {
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't load marble.bmp", NULL);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Bitmap_Init: couldn't create tibia texture", NULL);
|
||||||
return false;
|
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.
|
// TODO: Note: here, on the original client, it created a offscreen buffer of 36x36 pixels.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap_Destroy(const Bitmap_t* bitmap) {
|
void Bitmap_Destroy(const Bitmap_t* bitmap) {
|
||||||
SDL_DestroySurface(bitmap->tibiaSurface);
|
SDL_DestroyTexture(bitmap->tibiaTexture);
|
||||||
SDL_DestroySurface(bitmap->marbleSurface);
|
SDL_DestroyTexture(bitmap->marbleTexture);
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_Destroy: surfaces destroyed.");
|
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Bitmap_Destroy: surfaces destroyed.");
|
||||||
}
|
}
|
||||||
|
|||||||
6
bitmap.h
6
bitmap.h
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#ifndef TIBIA_BITMAP_H
|
#ifndef TIBIA_BITMAP_H
|
||||||
#define TIBIA_BITMAP_H
|
#define TIBIA_BITMAP_H
|
||||||
#include <SDL3/SDL_surface.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
typedef struct Bitmap {
|
typedef struct Bitmap {
|
||||||
SDL_Surface* tibiaSurface;
|
SDL_Texture* tibiaTexture;
|
||||||
SDL_Surface* marbleSurface;
|
SDL_Texture* marbleTexture;
|
||||||
} Bitmap_t ;
|
} Bitmap_t ;
|
||||||
|
|
||||||
bool Bitmap_Init(Bitmap_t* bitmap);
|
bool Bitmap_Init(Bitmap_t* bitmap);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
// Created by rov on 12/27/25.
|
// Created by rov on 12/27/25.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Objects.h"
|
#include "objects.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
35
render.c
35
render.c
@ -5,10 +5,41 @@
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
void Render_Frame() {
|
void Render_Frame(const App_t *app) {
|
||||||
SDL_Renderer* renderer = Window_GetRenderer();
|
SDL_Renderer *renderer = Window_GetRenderer();
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
Render_MainWindowBackground(app);
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
8
render.h
8
render.h
@ -4,7 +4,13 @@
|
|||||||
|
|
||||||
#ifndef TIBIA_RENDER_H
|
#ifndef TIBIA_RENDER_H
|
||||||
#define 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
|
#endif //TIBIA_RENDER_H
|
||||||
Loading…
x
Reference in New Issue
Block a user