#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
int main() {
// Crear la ventana
sf::RenderWindow window(sf::VideoMode(800, 600), "Reloj digital");
// Cargar la fuente
sf::Font font;
if (!font.loadFromFile("arial.ttf")) {
std::cerr << "Error al cargar la fuente" << std::endl;
return -1;
}
// Crear el texto para el reloj
sf::Text clockText;
clockText.setFont(font);
clockText.setCharacterSize(50);
clockText.setFillColor(sf::Color::White);
clockText.setPosition(300, 250);
// Cargar una imagen BMP o GIF
sf::Texture texture;
if (!texture.loadFromFile("imagen.bmp")) {
std::cerr << "Error al cargar la imagen" << std::endl;
return -1;
}
sf::Sprite sprite(texture);
sprite.setPosition(0, 0);
// Bucle principal
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
// Obtener la hora actual
std::time_t now = std::time(nullptr);
std::tm* localTime = std::localtime(&now);
std::ostringstream oss;
oss << std::put_time(localTime, "%H:%M:%S");
clockText.setString(oss.str());
// Limpiar la ventana
window.clear();
window.draw(sprite); // Dibujar la imagen
window.draw(clockText); // Dibujar el texto del reloj
window.display();
}
return 0;
}