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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lampcord

Pages: [1]
1
Graphics / Text alignment issues
« on: June 04, 2015, 01:33:37 am »
I'm having a little trouble with text alignment. So I did a little experiment and saw some confusing results.

I decided to draw a rectangle using the position of the text and the bounding rect of the text and then drawing the text on top of it. I was surprised to see that although the rectangle appeared to be the same size as the text they did not align correctly.  The text appeared about 2 pixels to the right and 8 pixels down from rectangle. So I checked the origin of the text and it is set at 0,0 which I assume is the upper left corner.  Here's a snippet of my code if that helps:


text.setPosition(x, y);
sf::RectangleShape rec2;
rec2.setFillColor(sf::Color::White);
sf::FloatRect textsize = text.getLocalBounds();
rec2.setSize(sf::Vector2f(textsize.width, textsize.height));
rec2.setPosition(x,y);
rw.draw(rec2);
rw.draw(text);

I expected the text to be exactly bounded by the rectangle. Is there something obvious I'm missing? I can adjust by setting the text origin to -2,-8 but that seems kind of strange. Its almost as if they are using different coordinate systems but I'm not sure.


2
Graphics / Fastest way to update individual pixels
« on: May 28, 2015, 10:41:08 pm »
Hi all!

New to SFML.

Working on a program that paints individual pixels to the screen as opposed the the normal practice of drawing sprites or larger shapes.

What is the most efficient way to do this?

I see there are functions to draw shapes directly to the render window but nothing that I can find for individual points and drawing a line of length 0 seems like overkill.

Also, I see that you can set the individual color of a pixel in an image. Would it be faster to maintain an image in memory and set individual pixels on it and then once per frame just paste the whole image to the screen?

Any help would be greatly appreciated!


Pages: [1]