diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index a06b449..702b7bc 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -10,7 +10,7 @@ namespace ComSquare::PPU { - //! @brief The struct containing all the registers the PPU + //! @brief The class containing all the registers the PPU class PPU : public Memory::IMemory { private: //! @brief INIDISP Register (F-blank and Brightness) diff --git a/sources/Renderer/IRenderer.hpp b/sources/Renderer/IRenderer.hpp index 448043d..a33f515 100644 --- a/sources/Renderer/IRenderer.hpp +++ b/sources/Renderer/IRenderer.hpp @@ -18,6 +18,9 @@ namespace ComSquare::Renderer //! @brief Render the buffer to the window virtual void drawScreen() = 0; //! @brief Set a pixel to the coordinates x, y with the color rgba + //! @param x The x position of the window (0, 0 is the top left corner). + //! @param y The y position of the window (0, 0 is the top left corner). + //! @param rgba The color of the pixel (red, green, blue, alpha). virtual void putPixel(int x, int y, uint8_t rgba) = 0; }; } diff --git a/sources/Renderer/SFRenderer.cpp b/sources/Renderer/SFRenderer.cpp index ec6133d..70f2c8d 100644 --- a/sources/Renderer/SFRenderer.cpp +++ b/sources/Renderer/SFRenderer.cpp @@ -3,17 +3,29 @@ // #include "SFRenderer.hpp" +#include +#include +#include +#include +#include namespace ComSquare::Renderer { - void SFRenderer::setWindowName(std::string) + void SFRenderer::setWindowName(std::string newWindowName) { - + this->window.setTitle(newWindowName); } void SFRenderer::drawScreen() { + sf::Sprite sprite; + sf::Image image; + image.loadFromMemory(this->pixelBuffer, sizeof(sf::Uint8 *) * this->videoMode.height * this->videoMode.width * 4); + //image.LoadFromPixels(800, 600, this->pixelBuffer); + //sprite.SetImage(image); + //window.Draw(sprite); + //window.Display(); } void SFRenderer::putPixel(int x, int y, uint8_t rgba) @@ -22,4 +34,16 @@ namespace ComSquare::Renderer (void) y; (void) rgba; } + + SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS) + { + this->shouldExit = false; + this->videoMode = {static_cast(width), static_cast(height), 32}; + // note 32 is the BitsPerPixel. + this->pixelBuffer = new sf::Uint8[height * width * 4]; + // note the size of the buffer is multiplied by 4 due to rgba values + this->window.create(this->videoMode, "ComSquare Emulator", sf::Style::Default); + this->window.setFramerateLimit(maxFPS); + } + } diff --git a/sources/Renderer/SFRenderer.hpp b/sources/Renderer/SFRenderer.hpp index cdc529d..d37e5cc 100644 --- a/sources/Renderer/SFRenderer.hpp +++ b/sources/Renderer/SFRenderer.hpp @@ -20,17 +20,24 @@ namespace ComSquare::Renderer sf::Window window; //! @brief Video Mode containing the height and width of the window. sf::VideoMode videoMode; + //! @brief The buffer containing all of our pixels + sf::Uint8 *pixelBuffer; public: //! @brief Set a new name to the window, if there is already a name it will be overwrite. - //! @param A new title for the window. - void setWindowName(std::string) override; + //! @param newWindowName new title for the window. + void setWindowName(std::string newWindowName) override; //! @brief Update the screen by printing the buffer. void drawScreen() override; //! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba. //! @param X horizontal index. //! @param Y vertical index. - //! @param rgba : The color of the pixel. + //! @param rgba The color of the pixel. void putPixel(int x, int y, uint8_t rgba) override ; + //! @brief Constructor that return the window component of the SFML. + //! @param height height of the window. + //! @param width width of the window. + //! @param maxFPS the number of maximum FPS for the window. + SFRenderer(unsigned int height, unsigned int width, int maxFPS); }; }