diff --git a/main.cpp b/main.cpp index daf9fa6..4011da1 100644 --- a/main.cpp +++ b/main.cpp @@ -20,8 +20,17 @@ int main(int argc, char **argv) Renderer::SFRenderer renderer(600, 800, 60); SNES snes(std::make_shared(bus), argv[1], renderer); bus.mapComponents(snes); + int incx = 0; + int incy = 0; + uint32_t pixel = 0xFF0000FF; while (!renderer.shouldExit) { + renderer.putPixel(incy, incx++, pixel); + if (incx >= 800) { + incx = 0; + incy++; + } + renderer.drawScreen(); renderer.getEvents(); } diff --git a/sources/Renderer/IRenderer.hpp b/sources/Renderer/IRenderer.hpp index 2ac7c37..c175e57 100644 --- a/sources/Renderer/IRenderer.hpp +++ b/sources/Renderer/IRenderer.hpp @@ -21,7 +21,7 @@ namespace ComSquare::Renderer //! @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; + virtual void putPixel(int x, int y, uint32_t rgba) = 0; }; } diff --git a/sources/Renderer/SFRenderer.cpp b/sources/Renderer/SFRenderer.cpp index 62057c3..b63a20f 100644 --- a/sources/Renderer/SFRenderer.cpp +++ b/sources/Renderer/SFRenderer.cpp @@ -14,37 +14,43 @@ namespace ComSquare::Renderer { void SFRenderer::setWindowName(std::string newWindowName) { - this->window.setTitle(newWindowName + " - ComSquare"); + this->renderer.setTitle(newWindowName + " - ComSquare"); } void SFRenderer::drawScreen() { - this->texture.update(this->pixelBuffer); - this->sprite.setTexture(this->texture, false); + this->texture.update(reinterpret_cast(this->pixelBuffer)); + this->sprite.setTexture(this->texture); this->renderer.draw(this->sprite); + this->renderer.display(); } - void SFRenderer::putPixel(int x, int y, uint8_t rgba) + void SFRenderer::putPixel(int x, int y, uint32_t rgba) { - this->pixelBuffer[this->videoMode.width * x + y] = rgba; + sf::Color pixels; + pixels.r = rgba >> 24U; + pixels.g = rgba >> 16U; + pixels.b = rgba >> 8U; + pixels.a = rgba >> 0U; + this->pixelBuffer[this->videoMode.width * x + y] = pixels; } SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS) { + sf::Color color(0, 0, 0); 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); + this->videoMode = {width, height, 32}; + this->renderer.create(this->videoMode, "ComSquare Emulator", sf::Style::Default); + this->renderer.setFramerateLimit(maxFPS); this->texture.create(width, height); + this->sprite.setTexture(this->texture); + this->pixelBuffer = new sf::Color[height * width]; } void SFRenderer::getEvents() { sf::Event event; - while (this->window.pollEvent(event)) { + while (this->renderer.pollEvent(event)) { if (event.type == sf::Event::Closed) { this->shouldExit = true; break; diff --git a/sources/Renderer/SFRenderer.hpp b/sources/Renderer/SFRenderer.hpp index e643847..c8997e4 100644 --- a/sources/Renderer/SFRenderer.hpp +++ b/sources/Renderer/SFRenderer.hpp @@ -16,18 +16,16 @@ namespace ComSquare::Renderer { class SFRenderer : public IRenderer { private: - //! @brief The main Window. - sf::Window window; //! @brief The Renderer for the window. sf::RenderWindow renderer; //! @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; - //! @brief The texture to render the array of pixels - sf::Texture texture; + //! @brief The image that contain all of the pixels + sf::Color *pixelBuffer; //! @brief The sprite to render the array of pixels sf::Sprite sprite; + //! @brief The texture to render the array of pixels + sf::Texture texture; public: //! @brief Set a new name to the window, if there is already a name it will be overwrite. //! @param newWindowName new title for the window. @@ -38,7 +36,7 @@ namespace ComSquare::Renderer //! @param X horizontal index. //! @param Y vertical index. //! @param rgba The color of the pixel. - void putPixel(int x, int y, uint8_t rgba) override ; + void putPixel(int x, int y, uint32_t rgba) override ; //! @brief Get the inputs from the Window void getEvents(); //! @brief Constructor that return the window component of the SFML.