Update main.cpp

changed to using smart pointer for window in main()
This commit is contained in:
2025-01-31 13:29:42 -05:00
parent 9f4b8987c0
commit ca55970ed9

View File

@@ -7,12 +7,18 @@
#include <rewindow/types/window.h>
#include <rewindow/logger/logger.h>
#include <GL/gl.h>
#include <memory>
#include <cmath>
#include <cstdlib>
#include <iostream>
// define window size and dot size (dot size should be odd)
// Define window size and dot size (dot size should be odd)
#define WIDTH 800
#define HEIGHT 600
#define DOT_SIZE 5
#define DEBUG 0
struct Walker {
float x, y;
@@ -26,25 +32,33 @@ struct Walker {
x = std::clamp(x + dx, 0.0f, static_cast<float>(WIDTH - 1));
y = std::clamp(y + dy, 0.0f, static_cast<float>(HEIGHT - 1));
#if DEBUG
std::cout << "Walker Position: (" << x << ", " << y << ")\n";
#endif
}
};
class RandomWalkerWindow : public ReWindow::RWindow {
public:
RandomWalkerWindow(const std::string& title, int width, int height)
: ReWindow::RWindow(title, width, height) {}
: ReWindow::RWindow(title, width, height), walker(std::make_unique<Walker>()) {}
void OnRefresh(float elapsed) override {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Clear with white
glClear(GL_COLOR_BUFFER_BIT);
walker->step(); // Move walker in each frame
GLSwapBuffers();
}
private:
std::unique_ptr<Walker> walker; // Use smart pointer for ownership
};
int main() {
std::unique_ptr<RandomWalkerWindow> window =
std::make_unique<RandomWalkerWindow>("Random Walker with ReWindow", WIDTH, HEIGHT);
auto window = std::make_unique<RandomWalkerWindow>("Random Walker with ReWindow", WIDTH, HEIGHT);
window->SetRenderer(RenderingAPI::OPENGL);
window->Open();