From 07be9e3a29d1776971e814dc592da059a6a1b9c4 Mon Sep 17 00:00:00 2001 From: "Ryan@WorkStation" Date: Thu, 14 Dec 2023 17:53:47 -0500 Subject: [PATCH] tested, can display image.png, no text --- .gitignore | 4 +++- statusDisplay/Makefile | 17 +++++++++++++++ statusDisplay/display.cpp | 46 ++++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 statusDisplay/Makefile diff --git a/.gitignore b/.gitignore index 34d7435..7a6b462 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -display \ No newline at end of file +display + +.gdb_history \ No newline at end of file diff --git a/statusDisplay/Makefile b/statusDisplay/Makefile new file mode 100644 index 0000000..f6c81e2 --- /dev/null +++ b/statusDisplay/Makefile @@ -0,0 +1,17 @@ +# Compiler +CXX = g++ +# Flags +CXXFLAGS = -Wall -Wextra -pedantic -std=c++11 +# Libraries +LIBS = -lSDL2 -lSDL2_image -lSDL2_ttf + +# Executable name +EXECUTABLE = display + +all: $(EXECUTABLE) + +$(EXECUTABLE): display.cpp + $(CXX) $(CXXFLAGS) -o $(EXECUTABLE) display.cpp $(LIBS) + +clean: + rm -f $(EXECUTABLE) diff --git a/statusDisplay/display.cpp b/statusDisplay/display.cpp index 45a5d7c..fc6e367 100644 --- a/statusDisplay/display.cpp +++ b/statusDisplay/display.cpp @@ -11,7 +11,7 @@ int main() { SDL_Window* window = SDL_CreateWindow("Image with Text Overlay", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 640, 480, 0); + 1577, 695, 0); // Create a renderer SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); @@ -23,40 +23,42 @@ int main() { // Font initialization for rendering text TTF_Init(); - TTF_Font* font = TTF_OpenFont("/usr/share/fonts/trutype/freefont/FreeMono.ttf", 24); + TTF_Font* font = TTF_OpenFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 24); SDL_Color textColor = { 255, 255, 255 }; // White color - SDL_Rect imageRect = { 0, 0, 640, 480 }; // Image position and size + SDL_Rect imageRect = { 0, 0, 1577, 695 }; // Image position and size SDL_Event event; bool running = true; while (running) { - while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) { - running = false; - } - } + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } - // Clear the renderer - SDL_RenderClear(renderer); + // Clear the renderer + SDL_RenderClear(renderer); - // Render the image - SDL_RenderCopy(renderer, texture, NULL, &imageRect); + // Render the image + SDL_RenderCopy(renderer, texture, NULL, &imageRect); - // Render text - std::string textToRender = "Dynamic Number: 123"; // Replace with your dynamic number - SDL_Surface* textSurface = TTF_RenderText_Solid(font, textToRender.c_str(), textColor); - SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); + // Render text + std::string textToRender = "Dynamic Number: 123"; // Replace with your dynamic number + SDL_Surface* textSurface = TTF_RenderText_Solid(font, textToRender.c_str(), textColor); - SDL_Rect textRect = { 50, 50, textSurface->w, textSurface->h }; // Position of text - SDL_RenderCopy(renderer, textTexture, NULL, &textRect); - SDL_FreeSurface(textSurface); - SDL_DestroyTexture(textTexture); + SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); - // Update the screen - SDL_RenderPresent(renderer); + SDL_Rect textRect = { 50, 50, textSurface->w, textSurface->h }; // Position of text + SDL_RenderCopy(renderer, textTexture, NULL, &textRect); + + SDL_FreeSurface(textSurface); + SDL_DestroyTexture(textTexture); + + // Update the screen + SDL_RenderPresent(renderer); } // Clean up