if you putpixel outside the screen you will sigfault

This commit is contained in:
Clément Le Bihan
2020-02-05 11:34:17 +01:00
parent 3282944c75
commit cc2b18314a
3 changed files with 15 additions and 10 deletions
+8 -2
View File
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
bus.mapComponents(snes);
int incx = 0;
int incy = 0;
uint32_t pixel = 0xFFFF00FF;
uint32_t pixel = 0x000000FF;
while (!renderer.shouldExit) {
renderer.putPixel(incy, incx++, pixel);
@@ -30,7 +30,13 @@ int main(int argc, char **argv)
incx = 0;
incy++;
}
renderer.drawScreen();
if (incy >= 600) {
incy = 0;
}
if (incx == 0) {
renderer.drawScreen();
pixel += 0xFF00FF00;
}
renderer.getEvents();
}
+6 -7
View File
@@ -14,15 +14,15 @@ namespace ComSquare::Renderer
{
void SFRenderer::setWindowName(std::string newWindowName)
{
this->renderer.setTitle(newWindowName + " - ComSquare");
this->window.setTitle(newWindowName + " - ComSquare");
}
void SFRenderer::drawScreen()
{
this->texture.update(reinterpret_cast<sf::Uint8 *>(this->pixelBuffer));
this->sprite.setTexture(this->texture);
this->renderer.draw(this->sprite);
this->renderer.display();
this->window.draw(this->sprite);
this->window.display();
}
void SFRenderer::putPixel(int y, int x, uint32_t rgba)
@@ -37,11 +37,10 @@ namespace ComSquare::Renderer
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
{
sf::Color color(0, 0, 0);
this->shouldExit = false;
this->videoMode = {width, height, 32};
this->renderer.create(this->videoMode, "ComSquare Emulator", sf::Style::Default);
this->renderer.setFramerateLimit(maxFPS);
this->window.create(this->videoMode, "ComSquare Emulator", sf::Style::Default);
this->window.setFramerateLimit(maxFPS);
this->texture.create(width, height);
this->sprite.setTexture(this->texture);
this->pixelBuffer = new sf::Color[height * width];
@@ -50,7 +49,7 @@ namespace ComSquare::Renderer
void SFRenderer::getEvents()
{
sf::Event event;
while (this->renderer.pollEvent(event)) {
while (this->window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
this->shouldExit = true;
break;
+1 -1
View File
@@ -17,7 +17,7 @@ namespace ComSquare::Renderer
class SFRenderer : public IRenderer {
private:
//! @brief The Renderer for the window.
sf::RenderWindow renderer;
sf::RenderWindow window;
//! @brief Video Mode containing the height and width of the window.
sf::VideoMode videoMode;
//! @brief The image that contain all of the pixels