Skip to content

Commit

Permalink
fix #148 support variable texture sizes in device disconnected screen
Browse files Browse the repository at this point in the history
  • Loading branch information
laamaa committed Jun 15, 2024
1 parent f40979e commit b7ca6e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
34 changes: 20 additions & 14 deletions src/fx_cube.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#include "SDL2_inprint.h"
#include "SDL_pixels.h"
#include "SDL_render.h"
#include <SDL.h>
#include <time.h>

#define target_width 320
#define target_height 240
static SDL_Texture *texture_cube;
static SDL_Texture *texture_text;
static SDL_Renderer *fx_renderer;
static SDL_Color line_color;

const char *text_m8c = "M8C";
const char *text_disconnected = "DEVICE DISCONNECTED";

static const float center_x = (float)target_width / 2;
static const float center_y = (float)target_height / 2;
static unsigned int center_x = 320 / 2;
static unsigned int center_y = 240 / 2;

static const float default_nodes[8][3] = {{-1, -1, -1}, {-1, -1, 1}, {-1, 1, -1}, {-1, 1, 1},
{1, -1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}};
Expand Down Expand Up @@ -51,24 +48,30 @@ static void rotate_cube(float angle_x, float angle_y) {
}
}

void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color) {
void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color,
unsigned int texture_width, unsigned int texture_height,
unsigned int font_glyph_width) {

fx_renderer = target_renderer;
line_color = foreground_color;
SDL_Point texture_size;

SDL_Texture *og_target = SDL_GetRenderTarget(fx_renderer);

SDL_QueryTexture(og_target, NULL, NULL, &texture_size.x, &texture_size.y);

texture_cube = SDL_CreateTexture(fx_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET,
target_width, target_height);
texture_size.x, texture_size.y);
texture_text = SDL_CreateTexture(fx_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET,
target_width, target_height);

SDL_Texture *og_target = SDL_GetRenderTarget(fx_renderer);
texture_size.x, texture_size.y);

SDL_SetRenderTarget(fx_renderer, texture_text);
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(fx_renderer);

inprint(fx_renderer, text_disconnected, 130, 228, 0xFFFFFF, 0x000000);
inprint(fx_renderer, text_m8c, 2, 2, 0xFFFFFF, 0x000000);
inprint(fx_renderer, "DEVICE DISCONNECTED", texture_width - font_glyph_width * 19 - 21,
texture_height - 12, 0xFFFFFF, 0x000000);
inprint(fx_renderer, "M8C", 2, 2, 0xFFFFFF, 0x000000);

SDL_SetRenderTarget(fx_renderer, og_target);

Expand All @@ -80,6 +83,9 @@ void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color) {

SDL_SetTextureBlendMode(texture_cube, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture_text, SDL_BLENDMODE_BLEND);

center_x = texture_size.x / 2.0;
center_y = texture_size.y / 2.0;
}

void fx_cube_destroy() {
Expand Down
4 changes: 3 additions & 1 deletion src/fx_cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define FX_CUBE_H_

#include "SDL_render.h"
void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color);
void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color,
unsigned int texture_width, unsigned int texture_height,
unsigned int font_glyph_width);
void fx_cube_destroy();
void fx_cube_update();
#endif
3 changes: 2 additions & 1 deletion src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ void render_screen() {

void screensaver_init() {
set_font_mode(1);
fx_cube_init(rend, (SDL_Color){255, 255, 255, 255});
fx_cube_init(rend, (SDL_Color){255, 255, 255, 255}, texture_width, texture_height,
fonts[font_mode]->glyph_x);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Screensaver initialized");
}

Expand Down

0 comments on commit b7ca6e7

Please sign in to comment.