tested, can display image.png, no text
This commit is contained in:
parent
e4d93f6d51
commit
07be9e3a29
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
display
|
display
|
||||||
|
|
||||||
|
.gdb_history
|
17
statusDisplay/Makefile
Normal file
17
statusDisplay/Makefile
Normal file
|
@ -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)
|
|
@ -11,7 +11,7 @@ int main() {
|
||||||
SDL_Window* window = SDL_CreateWindow("Image with Text Overlay",
|
SDL_Window* window = SDL_CreateWindow("Image with Text Overlay",
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
640, 480, 0);
|
1577, 695, 0);
|
||||||
|
|
||||||
// Create a renderer
|
// Create a renderer
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
@ -23,40 +23,42 @@ int main() {
|
||||||
|
|
||||||
// Font initialization for rendering text
|
// Font initialization for rendering text
|
||||||
TTF_Init();
|
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_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;
|
SDL_Event event;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the renderer
|
// Clear the renderer
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Render the image
|
// Render the image
|
||||||
SDL_RenderCopy(renderer, texture, NULL, &imageRect);
|
SDL_RenderCopy(renderer, texture, NULL, &imageRect);
|
||||||
|
|
||||||
// Render text
|
// Render text
|
||||||
std::string textToRender = "Dynamic Number: 123"; // Replace with your dynamic number
|
std::string textToRender = "Dynamic Number: 123"; // Replace with your dynamic number
|
||||||
SDL_Surface* textSurface = TTF_RenderText_Solid(font, textToRender.c_str(), textColor);
|
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_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
|
||||||
SDL_DestroyTexture(textTexture);
|
|
||||||
|
|
||||||
// Update the screen
|
SDL_Rect textRect = { 50, 50, textSurface->w, textSurface->h }; // Position of text
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderCopy(renderer, textTexture, NULL, &textRect);
|
||||||
|
|
||||||
|
SDL_FreeSurface(textSurface);
|
||||||
|
SDL_DestroyTexture(textTexture);
|
||||||
|
|
||||||
|
// Update the screen
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
|
|
Loading…
Reference in New Issue
Block a user