SFML community forums

Help => General => Topic started by: Chrupiter on April 19, 2015, 06:15:09 pm

Title: [SOLVED]Draw in a 200x200 display which actually is 32x32
Post by: Chrupiter on April 19, 2015, 06:15:09 pm
Here's the issue.
I've an image of 32x32 pixels on which I can draw. But drawing in such a small window is really hard.
So I want this image to be displayed as a 200x200 image, but actually it must be 32x32.
For example, if you in Paint create a new image 32x32, then you zoom in, you get what I'm talking about.
But I don't wanna zoom in dynamically, I want it to be fixed 200x200, so that I'll still be able to export the image in 32x32.
I found the class view, but it allows me only to see a region zoomed, then when i try to draw the program crashes because it's as if i were drawing outside the image.
Thanks.
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: Nexus on April 19, 2015, 06:23:04 pm
So I want this image to be displayed as a 200x200 image, but actually it must be 32x32.
Create a 200x200 window with a 32x32 view. It's very simple, have a look at the view tutorial and documentation.

then when i try to draw the program crashes because it's as if i were drawing outside the image.
SFML doesn't crash when you draw outside the view. You do something else wrong.
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: Chrupiter on April 19, 2015, 06:29:40 pm
SFML doesn't crash when you draw outside the view. You do something else wrong.

It crashes because I draw outside the image like this:
Code: [Select]
//given image of 32x32
image.setPixel(mouse.x,mouse.y, color);

when x or y are bigger than 32 it crashes. Anyway, I'll try what you said, thanks.
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: Nexus on April 19, 2015, 06:39:24 pm
It crashes because I draw outside the image like this:
Code: [Select]
//given image of 32x32
image.setPixel(mouse.x,mouse.y, color);
That's not drawing, just setting pixels in a container.

Yes, of course you cannot access indices outside the image... It's the same with every array.
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: Chrupiter on April 19, 2015, 06:58:02 pm
I can't fix this. Even if I set the view, I can't draw correctly in it.
This is what happens to me:
(click to show/hide)
I draw where the mouse is, and the result on the view is not where i'd like it to be. It still gets my mouse coordinates from the 32x32 image on the top-left.
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: AlexxanderX on April 19, 2015, 09:24:26 pm
You have everything in tutorials: http://www.sfml-dev.org/tutorials/2.2/graphics-view.php#coordinates-conversions (http://www.sfml-dev.org/tutorials/2.2/graphics-view.php#coordinates-conversions)
Title: Re: Draw in a 200x200 display which actually is 32x32
Post by: Chrupiter on April 19, 2015, 09:49:45 pm
It worked, thanks. I had already tried that but it didn't work, now it does.