putpixel is working

This commit is contained in:
Clément Le Bihan
2020-02-04 18:59:11 +01:00
parent f93d505dc3
commit 3706e59d54
4 changed files with 33 additions and 20 deletions
+9
View File
@@ -20,8 +20,17 @@ int main(int argc, char **argv)
Renderer::SFRenderer renderer(600, 800, 60);
SNES snes(std::make_shared<Memory::MemoryBus>(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();
}
+1 -1
View File
@@ -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;
};
}
+18 -12
View File
@@ -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<sf::Uint8 *>(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<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);
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;
+5 -7
View File
@@ -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.