mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-21 14:45:10 +00:00
SFRenderer and setWindowName added and a documentation fix
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace ComSquare::PPU
|
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 {
|
class PPU : public Memory::IMemory {
|
||||||
private:
|
private:
|
||||||
//! @brief INIDISP Register (F-blank and Brightness)
|
//! @brief INIDISP Register (F-blank and Brightness)
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ namespace ComSquare::Renderer
|
|||||||
//! @brief Render the buffer to the window
|
//! @brief Render the buffer to the window
|
||||||
virtual void drawScreen() = 0;
|
virtual void drawScreen() = 0;
|
||||||
//! @brief Set a pixel to the coordinates x, y with the color rgba
|
//! @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;
|
virtual void putPixel(int x, int y, uint8_t rgba) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,29 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "SFRenderer.hpp"
|
#include "SFRenderer.hpp"
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <SFML/System.hpp>
|
||||||
|
#include <SFML/Window.hpp>
|
||||||
|
#include <SFML/Graphics//RenderWindow.hpp>
|
||||||
|
|
||||||
namespace ComSquare::Renderer
|
namespace ComSquare::Renderer
|
||||||
{
|
{
|
||||||
void SFRenderer::setWindowName(std::string)
|
void SFRenderer::setWindowName(std::string newWindowName)
|
||||||
{
|
{
|
||||||
|
this->window.setTitle(newWindowName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFRenderer::drawScreen()
|
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)
|
void SFRenderer::putPixel(int x, int y, uint8_t rgba)
|
||||||
@@ -22,4 +34,16 @@ namespace ComSquare::Renderer
|
|||||||
(void) y;
|
(void) y;
|
||||||
(void) rgba;
|
(void) rgba;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
|
||||||
|
{
|
||||||
|
this->shouldExit = false;
|
||||||
|
this->videoMode = {static_cast<unsigned int>(width), static_cast<unsigned int>(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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,24 @@ namespace ComSquare::Renderer
|
|||||||
sf::Window window;
|
sf::Window window;
|
||||||
//! @brief Video Mode containing the height and width of the window.
|
//! @brief Video Mode containing the height and width of the window.
|
||||||
sf::VideoMode videoMode;
|
sf::VideoMode videoMode;
|
||||||
|
//! @brief The buffer containing all of our pixels
|
||||||
|
sf::Uint8 *pixelBuffer;
|
||||||
public:
|
public:
|
||||||
//! @brief Set a new name to the window, if there is already a name it will be overwrite.
|
//! @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.
|
//! @param newWindowName new title for the window.
|
||||||
void setWindowName(std::string) override;
|
void setWindowName(std::string newWindowName) override;
|
||||||
//! @brief Update the screen by printing the buffer.
|
//! @brief Update the screen by printing the buffer.
|
||||||
void drawScreen() override;
|
void drawScreen() override;
|
||||||
//! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba.
|
//! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba.
|
||||||
//! @param X horizontal index.
|
//! @param X horizontal index.
|
||||||
//! @param Y vertical 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 ;
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user