tested, can display image.png, no text
This commit is contained in:
parent
e4d93f6d51
commit
07be9e3a29
4
.gitignore
vendored
4
.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_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
|
||||
|
|
Loading…
Reference in New Issue
Block a user