I'm using CSFML as a graphics library for my project.
I'm trying to draw a sfRectangleShape on the screen but it seems like the drawing isn't occurring.
I've tried to clear the window with a different color just to check if the window actually updates when it needs to, and it does work.
This is how I draw things on the window:
int draw(CPU* cpu) {
/* Clear the window before displaying the new frame. */
sfRenderWindow_clear(_window, sfBlack);
/* Iterate through the GFX display array. */
for (unsigned int line = 0; line < GFX_HORIZONTAL; line++) {
for (unsigned int col = 0; col < GFX_VERTICAL; col++) {
/* Check if current pixel is set. */
if (cpu->gfx[col + (line * GFX_HORIZONTAL)]) {
/* Draw the pixel on the screen. */
sfVector2f position = {col * SCALE_FACTOR, line * SCALE_FACTOR};
sfRectangleShape_setPosition(_pixel, position);
sfRectangleShape_setFillColor(_pixel, sfRed);
sfRenderWindow_drawRectangleShape(_window, _pixel, 0);
}
}
}
sfRenderWindow_display(_window);
return 0;
}
_window, _scale and _pixel are declared as follows:
static sfRenderWindow* _window = 0;
static sfRectangleShape* _pixel = 0;
static sfVector2f _scale = {SCALE_FACTOR, SCALE_FACTOR}; //SCALE_FACTOR is defined as 16.
The window is opened in another function, and as I said, changing the color used for sfRenderWindow_clear does work and change the screen's color, so the rest should work too, but the screen is always blank and never displays the rectangles representing the pixels.
I'm a beginner to SFML and especially to CSFML so I might (probably what happened) done something completely wrong and that's what causing the issue.
My question is, am I doing something wrong? How can I fix this? Followed the tutorials and converted the code to C (and not C++) myself using the CSFML source code repo.