Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: CSFML window not drawing rectangle shape  (Read 3914 times)

0 Members and 1 Guest are viewing this topic.

MEG4

  • Newbie
  • *
  • Posts: 2
    • View Profile
CSFML window not drawing rectangle shape
« on: May 22, 2021, 04:00:53 pm »
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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: CSFML window not drawing rectangle shape
« Reply #1 on: May 22, 2021, 05:52:13 pm »
Have you set the size of your rectangle?

MEG4

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: CSFML window not drawing rectangle shape
« Reply #2 on: May 22, 2021, 07:14:07 pm »
Yes I have. It is created and it's scale is set in another function.

 

anything