diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34d7435 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +display \ No newline at end of file diff --git a/statusDisplay/README.md b/statusDisplay/README.md new file mode 100644 index 0000000..e26b5b8 --- /dev/null +++ b/statusDisplay/README.md @@ -0,0 +1,7 @@ +The Status Display on Raspberry Pi use the SDL C++ library + + sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev + +To Compile + + g++ -o display display.cpp -lSDL2 -lSDL2_image -lSDL2_ttf diff --git a/statusDisplay/display.cpp b/statusDisplay/display.cpp new file mode 100644 index 0000000..45a5d7c --- /dev/null +++ b/statusDisplay/display.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include + +int main() { + SDL_Init(SDL_INIT_VIDEO); + + // Create a window + SDL_Window* window = SDL_CreateWindow("Image with Text Overlay", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 640, 480, 0); + + // Create a renderer + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + + // Load an image + SDL_Surface* imageSurface = IMG_Load("image.png"); + SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, imageSurface); + SDL_FreeSurface(imageSurface); + + // Font initialization for rendering text + TTF_Init(); + TTF_Font* font = TTF_OpenFont("/usr/share/fonts/trutype/freefont/FreeMono.ttf", 24); + SDL_Color textColor = { 255, 255, 255 }; // White color + + SDL_Rect imageRect = { 0, 0, 640, 480 }; // Image position and size + + SDL_Event event; + bool running = true; + + while (running) { + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } + + // Clear the renderer + SDL_RenderClear(renderer); + + // 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); + + 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 + SDL_DestroyTexture(texture); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + + return 0; +} \ No newline at end of file diff --git a/statusDisplay/image.png b/statusDisplay/image.png new file mode 100644 index 0000000..2e17a2d Binary files /dev/null and b/statusDisplay/image.png differ