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

Author Topic: Unexpected result while drawing pixels  (Read 2013 times)

0 Members and 1 Guest are viewing this topic.

motherbrain

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unexpected result while drawing pixels
« on: February 27, 2010, 02:15:51 pm »
Hi,

I'm new to SFML and I got some unexpected results running my first test code:

Code: [Select]
#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
const unsigned int width = 200;
const unsigned int height = width;

RenderWindow app(VideoMode(width, height, 32), "");

Image image(width, height);
Sprite sprite(image);

const unsigned int step = 2;
for (unsigned int y = 0; y <= height - step; y += step)
{
for (unsigned int x = 0; x <= width - step; x += step)
{
image.SetPixel(x, y, Color::White);
}
}

app.Draw(sprite);
app.Display();

while (app.IsOpened())
{
Event event;
while (app.GetEvent(event))
{
if (event.Type == Event::Closed)
{
app.Close();
}
}
}

return EXIT_SUCCESS;
}


The resulting image is not what I would expect: the pixels become gray and blurry towards the edges of the image. What is causing this and how can I prevent it? I'm using SFML version 1.5 under Windows 7 64 bit with an ATI Radeon 5770 graphics card with the latest display drivers.

I would like to mix drawing shapes (using sf::Shape::Line, sf::Shape::Circle and sf::Shape::Rectangle) and pixels: draw some shapes, then draw some pixels, draw some more shapes, etc, and then display the results. What is a good approach to draw the pixels in this case?

motherbrain

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unexpected result while drawing pixels
« Reply #1 on: February 27, 2010, 03:13:22 pm »
I have uploaded a screenshot that shows the problem: click

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Unexpected result while drawing pixels
« Reply #2 on: February 27, 2010, 03:16:42 pm »
With the following code, you can deactivate the smooth filter (which is enabled by default):
Code: [Select]
image.SetSmooth(false);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

motherbrain

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unexpected result while drawing pixels
« Reply #3 on: February 27, 2010, 03:21:19 pm »
Thanks! This solved my first problem. But why is the image in the center different from the edges when the smooth filter is active?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Unexpected result while drawing pixels
« Reply #4 on: February 27, 2010, 04:57:16 pm »
This is a pattern which is produced by the filtering method.
Laurent Gomila - SFML developer