# Anyone know SFML to answer this screen mapping question?

yungman
Hi

I am just starting to studying games with C++ by Horton for a few days. It uses SFML for graphics, sound and fonts. I am puzzled with the screen map location. In the program below, you can see the resolution is 1920 X 1080 full screen. But there are something funny when I create a sprite and put it in specified location. I actually took a picture with camera and screen capture and write the coordinates where I put the tree (810, 0)and the bee(400,510). But if I count on the resolution of 1920 X 1080, as I labeled top left is (0,0), bottom right is (1920, 1080), it way off!

This is the program
C++:
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
int main()
{   VideoMode vm(1920, 1080);//set screen resolution 1920 X 1080
RenderWindow window(vm, "Timber!", Style::Fullscreen);//create window object
Texture textureBackground;//Create texture to hold graphic on GPU
Sprite spriteBackground;//create a sprite
spriteBackground.setTexture(textureBackground);//attach texture to sprite
spriteBackground.setPosition(0, 0);//set sprite to cover the screen

Texture textureTree;
Sprite spriteTree;
spriteTree.setTexture(textureTree);
spriteTree.setPosition(810, 0);//810 should put a little left from center

Texture textureBee;
Sprite spriteBee;
spriteBee.setTexture(textureBee);
spriteBee.setPosition(400, 510);
bool beeActive = false;
float beeSpeed = 0.0f;

Texture textureCloud;
Sprite spriteCloud1;
Sprite spriteCloud2;
Sprite spriteCloud3;
spriteCloud1.setTexture(textureCloud);
spriteCloud2.setTexture(textureCloud);
spriteCloud3.setTexture(textureCloud);
spriteCloud1.setPosition(0, 0);
spriteCloud2.setPosition(0, 250);
spriteCloud3.setPosition(0, 500);
bool cloud1Active = false;
bool cloud2Active = false;
bool cloud3Active = false;
float cloud1Speed = 0.0f;
float cloud2Speed = 0.0f;
float cloud3Speed = 0.0f;
window.clear();
window.draw(spriteBackground);
window.draw(spriteTree);
window.draw(spriteBee);
window.draw(spriteCloud1);
window.draw(spriteCloud2);
window.draw(spriteCloud3);
window.display();//Update screen with new background
while (window.isOpen())//Stay looping until ESC
{ if (Keyboard::isKeyPressed(Keyboard::Escape))
{ window.close(); }//Hit ESC key to exit
}
window.clear();
window.display();
return 0;
}

you can see I see the coordinates of the sprite of tree at (810,0) in line 18. and sprite of bee is (400, 510) in line 24. Why the sprites display so off on the screen? Got to have a very simple explanation why I am off that I missed.

Thanks

yungman
I found out what really is wrong. I still don't know how to fix it. This is the image from the book running the program ( I change the position of the bee, everything else is the same position). The book is cheap to only have black and white picture!

This looks correct. The problem is my screen ONLY display part of the picture as shown with the red outline. You can see the part below the tree is not shown in my program with my computer.

It must be some sort of setup problem that when the program is set to full screen, it ZOOM in too much and cut out the higher number of x and y. That's why my image is off. Must be the setting in line 7 in the program in post 1 is off.

Any suggestion?

thanks

EDIT: I checked my laptop, it can only set to 1366 X 768 resolution. Maybe that's the problem.

Last edited:
Mentor
EDIT: I checked my laptop, it can only set to 1366 X 768 resolution. Maybe that's the problem.
Ya think?

yungman
Ya think?
I have no idea how to fix this. I tried changing line 6 VideoMode vm(1920, 1080) to match, it did not work. I tried other numbers also, it doesn't seem to make any difference.

I tried going to computer->setting-> display and play with these, it didn't work either

Anything I can try?

Thanks

Staff Emeritus
A book on SFML is unlikely to contain instructions on how to operate your laptop.
If your laptop screen has a maximum resolution of 1366x768 you will not be able to set a mode of 1920x1080.

yungman
A book on SFML is unlikely to contain instructions on how to operate your laptop.
If your laptop screen has a maximum resolution of 1366x768 you will not be able to set a mode of 1920x1080.
Thanks

I tried everything on my laptop. Nothing work.

I understand this is a programming forum, not SFML graphics forum. I just join the SFML forum and trying to ask the same question in the SFML forum, hopefully I can get it resolved.

Thanks

Staff Emeritus
I tried everything on my laptop. Nothing work.

That's because if your laptop screen has a maximum resolution of 1366x768 you will not be able to set a mode of 1920x1080.

yungman
That's because if your laptop screen has a maximum resolution of 1366x768 you will not be able to set a mode of 1920x1080.
I tried setting the program resolution to 1366 X 768 in line 6 of the program in post 1. That was the first thing I tried. It did not work. I think the image is programmed to be 1920X1080. So the image is bigger.

I have a sinking feeling I need to buy a new laptop. I am going to confirm with the staff in SFML. When I bought this laptop, I did not think about video games. I hate video games, I want to learn this just for the graphics.

Thanks

yungman
I am pretty sure it's my laptop. I put the bee in (683, 384) which is half way of (1366, 768). I have the stupid bee at DEAD CENTER!

So this is the end of the road unless I can change the image of the .png file to conform to 1366 X 768. is there any way to do that? I am born cheap, I don't want to buy a new laptop, this is only 7 months old! This was not a cheap computer by any stretch, I got a lot of good stuffs on this, just not graphics. I think I paid like $700 for this. It's like 512G SSD drive and 8G rams and latest gen I-5 at the time. Mentor It's in PNG (portable network graphics) format, so you can edit the image in, say, Paint, to change its size, to get the width and height down to 1366 pixels by 768 pixels. yungman I think I got the answer from SFML, I have to read about sf::view, view is a class in SFML and view has member function for setting center and all sort of stuffs. This is the link I am reading now. Maybe you guys might find interesting: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1View.php My question to you guys is this. I am really trying to learn graphics, I am not exactly interested in gaming. 1) Can I use SFML for graphs, simulation and other stuffs other than games? 2) Is there any free more scientific graphics like SFML I can download? thanks yungman It's in PNG (portable network graphics) format, so you can edit the image in, say, Paint, to change its size, to get the width and height down to 1366 pixels by 768 pixels. Yes, I did try that, I can just size the background easily, but I have to size down each of the sprite to fit in the picture. eg. if the tree is 200X600, I have to multiply the number by (1366/1920) to get 142 X 427 to scale down the size of the tree. Then I have to know the new coordinates in 1366 X 768 on the screen. But I want to follow what suggested to me and read the class view of SFML first to see whether I can do it easier. Thanks Science Advisor Homework Helper Gold Member You are making life very difficult for yourself by trying to write software on such a small screen, no wonder you print everything out. It is simply not feasible to use development tools like Visual Studio effectively at less than 1920x1080. Assuming your lappy has an HDMI connection, spend <$200 (you are in the US, right?) on a decent 24" or peferably 27-28" monitor.

Staff Emeritus
spend <$200 (you are in the US, right?) on a decent 24" or peferably 27-28" monitor. And <$12 for a USB keyboard and mouse.

pbuk
yungman
Ha ha, you guys are spoiled. Talking about critical, I design complicated multi layers pcb on a 12" to 13" laptop for years. This is the first time I have a 15" laptop. I have big monitor like 22" or something, it's sitting in the closet. I saw mechanical engineer doing their design on laptops, I have not seen desktop and monitors for a long time at work.

Homework Helper
Gold Member
Using the right tool for the job is not 'being spoiled'.

Staff Emeritus
If you have a 1080p monitor in the closet and used it, as @pbuk suggested, you wouldn't have had this problem to begin with.

yungman
Using the right tool for the job is not 'being spoiled'.
We got the job done all these years. We are talking about really critical graphics in pcb design at work, so much more critical than games. Everyone use laptop. Nobody complain.

yungman
If you have a 1080p monitor in the closet and used it, as @pbuk suggested, you wouldn't have had this problem to begin with.
You mean the resolution follows the monitor, not the laptop? I did not know that.

Staff Emeritus
Well it's now 2021 and anyone who spends $100s on books and ink cartridges instead of plugging in a monitor he already owns because of some misplaced nostalgia is wasting his money and everyone's time. Vanadium 50 Science Advisor Homework Helper Gold Member Using the right tool for the job is not 'being spoiled'. Indeed! More screen real estate = more productive software development. Before Covid, when I used to work at an office (remember those?), I used three displays including my MacBook Pro screen, which itself has 3072x1920 resolution. I could easily have made good use of four or even five displays if my desk had room for them. I'm starting to understand why @yungman insists on using such a compressed coding style. Science Advisor Homework Helper Gold Member Ha ha, you guys are spoiled. Talking about critical, I design complicated multi layers pcb on a 12" to 13" laptop for years. This is the first time I have a 15" laptop. I have big monitor like 22" or something, it's sitting in the closet. I saw mechanical engineer doing their design on laptops, I have not seen desktop and monitors for a long time at work. Sounds like a cheap-*ss employer which fails to recognize that lost productivity is far more expensive than better equipment. Avoid such employers like the plague that they are. yungman We are very proud of what we accomplished with the little we had. We are in very high tech, literally a mini version of Stanford Linear Accelerator type type of technology , we beat out competitors. We did a lot with less. Till today, I have better electronic test equipment than they have in my home. When I was contracting with them a few years ago, I did all my testing at home, I didn't even have to go there. I still have a whole lab in one of my room. It's the brain, not the tools. Mentor ou are making life very difficult for yourself by trying to write software on such a small screen, no wonder you print everything out. This... And no wonder that you ask questions that were already answered several posts back in a thread. Ha ha, you guys are spoiled. Talking about critical, I design complicated multi layers pcb on a 12" to 13" laptop for years. This is the first time I have a 15" laptop. I have big monitor like 22" or something, it's sitting in the closet. Spoiled? I don't think so. Did you ever see a carpenter whose only tool was an axe? He probably wasn't making pianos, or for that matter, any structure more elegant than an outhouse. You've obviously never seen the setups that software developers use -- typically three, four, or more flat screen monitors of about 27" each. If I were you I would recycle the 22" monitor, and plunk down the money to get a 27" or larger flatscreen (~$175).