-
Running SFML 2.0 and Win7. My monitor's native resolution is 1650 x 1080 pixels which is what Win7's screen resolution is set to. The .png image I'm trying to display is 1650 x 1080.
When I set screen width=1650 and height=1080, only the console window displays but the RenderWindow does not display.
If I set width=1650 and height=900, the RenderWindow displays.
If I set width=1450 and height=900, the RenderWindow displays.
Why won't SFML's window display when I use width=1650 and height=1080?
Here's the applicable code:
// Main.cpp
int SCREEN_WIDTH = 1650;
int SCREEN_HEIGHT = 1080;
sf::RenderWindow App;
int _tmain(int argc, _TCHAR* argv[])
{
App.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "CRAPS");
while (App.isOpen())
{
switch (eGameState)
{
case SPLASH: // Show splash screen. Wait for user to click mouse, press a key, or click close.
{
SplashScreen splashScreen;
splashScreen.show(App);
eGameState = MAIN_MENU;
break;
}
// SplashScreen.cpp
sf::Texture image;
if (image.loadFromFile ("Images/Table1650x1080.png") != true)
{
return;
}
I'm using my splashScreen class to test display of the craptable in 1650x1080 size.
Also, I realize now that the size of the craptable has to be smaller than 1650x1080 to allow for SFML's window frame. How do I calculate the dimensions of the "Table1650x1080.png" image to fit within the RenderWindow's frame?
Thanks,
Raptor
-
Do
App.create(sf::VideoMode::getFullscreenModes()[0],"CRAPS",sf::Style::Fullscreen);
instead if you want 'real' full screen and make sure your video mode is not fubar for fullscreening.
App also shouldn't be global but inside main.
If you want to fit sprite of a texture bigger or smaller into entire window then scale sprite with origin 0,0 with window.x/texture.x and window.y/texture.y
-
https://github.com/SFML/SFML/issues/215
-
Hi FRex and Laurent,
Thank you very much for your replies. I found that my problem was caused by *OPERATOR ERROR* !
I had transposed the screen resolution values.
Should be: 1680 x 1050
I used.....: 1650 x 1080
The problem was that the vertical resolution of 1080 that I used was larger than the actual screen resolution of 1050. When I use the correct 1680 x 1050 resolution, the window displays, even without using a setPosition statement.
==========
Now I have another problem. When I use this code, the RenderWindow displays but the upper left corner of the RenderWindow does not display at screen position 0,0. I'm not referring to the display of the crap table within the SFML window. I mean the entire SFML window does not display at screen position 0,0. It displays centered on the screen.
int _tmain(int argc, _TCHAR* argv[])
{
int SCREEN_WIDTH = 1440;
int SCREEN_HEIGHT = 900;
sf::RenderWindow App; //Levelworld prog puts this before main.
App.setPosition(sf::Vector2i(0, 0)); //Set topleft corner of window to 0, 0.
Is my setPosition code incorrect?
PS: The image I'm using is 1440x900 in size so the entire crap table displays in the 1440x900 RenderWindow.
Thanks,
Raptor
-
I'm not really sure what you refere to with 'centered' and 'not display at screen position 0,0'.
The window has a border before the actual rendering part starts, afaik if you set it to 0,0 then the window will be set to 0,0 but it will include the border.
Why don't you just use fullscreen mode, since you want to cover the whole screen?
-
You call setPosition after creating the window, right?
-
You call setPosition after creating the window, right?
:D :D :D :D
Why don't you just use fullscreen mode, since you want to cover the whole screen?
This. Also these values for resolution are quite big imo, that'd not fit into my screen, if someone launches your game with smaller desktop resolution it'll not appear or display any error ordo anything at all. Just get one of valid video modes and run in fullscreen.
-
Hi eXpl0it3r, Laurent and FRex,
>>> You call setPosition after creating the window, right? <<<
Noob mistake :) Forgot that RenderWindow does not "create" the window. Moved setPosition where it should be and it works now.
>>> Why don't you just use fullscreen mode, since you want to cover the whole screen? <<<
>>> This. Also these values for resolution are quite big imo, that'd not fit into my screen, if someone launches your game with smaller desktop resolution it'll not appear or display any error ordo anything at all. Just get one of valid video modes and run in fullscreen. <<<
I created the crap table as 1680 x 1050 since when resizing down, there's no loss of apparent resolution, but resizing say a 640x480 screen larger would have to invent pixels so not look as good. (I think anyway.)
I also thought that using fullscreen mode would distort the image if the aspect ratio of the screen was not the same as the aspect ratio of the image. IOW, I thought it would stretch the image to fill the entire screen even if the aspect ratios didn't match. I just tried a 4:3 aspect image as full screen on my 16:10 monitor and now see that's not the case. SFML displays the 4:3 aspect image with a black bar on the right side so it retains the image's aspect ratio as it should.
QUESTIONS:
1. Can I continue to load my 1680x1050 image but use fullscreen mode to accomodate lower res monitors? Or do I need to load a 640x480 image and have fullscreen mode resize it larger to the user's screen resolution?
2. Is there an example of actual code to convert coordinates when fullscreen mode is used? (Or could some kind soul write an example here?) I had a hard time coming up with the actual code when I looked at the SFML 2.0 documentation on that before. --- My needs are simple. I just need to click on different parts of the crap table to choose chip values, make bets on the desired items like passline, field, any craps, etc. where the chip(s) appear where I click, etc. IOW, no sprite movements or shooting or stuff like that.
Thanks,
Raptor
-
Btw there's a whole quoting system with quote-tags etc. so you don't need to use some strange looking >>> and <<<... ;)
1. Can I continue to load my 1680x1050 image but use fullscreen mode to accomodate lower res monitors? Or do I need to load a 640x480 image and have fullscreen mode resize it larger to the user's screen resolution?
You can load the highres image and then resize it to fit the monitor resolution, but it may also be good to have diffrent resolution versions at hand (e.g. mipmapping), because the resize algorithm used by SFML/OpenGL might not be as good looking as one you can use in your favourite image editor. ;)
2. Is there an example of actual code to convert coordinates when fullscreen mode is used? (Or could some kind soul write an example here?) I had a hard time coming up with the actual code when I looked at the SFML 2.0 documentation on that before.
I'm not quite sure what you're asking here. What exactly do you want to convert?
When you're in fullscreen mode you 'own' the whole screen, i.e. the top left pixel is the 0,0 position of the rendering part.
If you want to prevent the stretching of the rendering area on widescreen monitors, then you should take a look at sf::View. I've written a tutorial (https://github.com/SFML/SFML/wiki/TutorialUsingView)on it that also includes a code example. ;)
-
Btw there's a whole quoting system with quote-tags etc. so you don't need to use some strange looking >>> and <<<... ;)
Yup, used the quoting system before. Was in a hurry (a "honey-do" now) thing so used the >>> <<< for multiple quotes from different people.
You can load the highres image and then resize it to fit the monitor resolution, but it may also be good to have diffrent resolution versions at hand (e.g. mipmapping), because the resize algorithm used by SFML/OpenGL might not be as good looking as one you can use in your favourite image editor. ;)
That's why I was thinking of having 3 or 4 different image resolutions available and use the one to fit the user's screen.
2. Is there an example of actual code to convert coordinates when fullscreen mode is used? (Or could some kind soul write an example here?) I had a hard time coming up with the actual code when I looked at the SFML 2.0 documentation on that before.
I'm not quite sure what you're asking here. What exactly do you want to convert?
When you're in fullscreen mode you 'own' the whole screen, i.e. the top left pixel is the 0,0 position of the rendering part.
If you want to prevent the stretching of the rendering area on widescreen monitors, then you should take a look at sf::View. I've written a tutorial (https://github.com/SFML/SFML/wiki/TutorialUsingView)on it that also includes a code example. ;)
What exactly do you want to convert?
Say a button on my crap table is at coordinate 700x, 700y on my 1680x1050 image. When I use fullscreen on a smaller monitor, won't that button be located at a different coordinate? Won't I have to convert coordinates for the smaller screen?
I'll take a look at your tutorial.
Thanks for the help!
Raptor
-
That's what convertcoords is for in render window, it'll give you the position of the click in sfml coordinates from sf::mouse or sf::event coordinates.
-
That's what convertcoords is for in render window, it'll give you the position of the click in sfml coordinates from sf::mouse or sf::event coordinates.
Thank you FRex.
I'm trying to figure out how to code convertCoords since I don't really understand how to decipher the class statements given in the SFML 2.0 documentation. Like:
Vector2f convertCoords (const Vector2i &point) const
Convert a point from target coordinates to view coordinates.
Thanks,
Raptor
-
There's also an explenation of it in my tutorial I linked earlier. ;)
-
There's also an explenation of it in my tutorial I linked earlier. ;)
I did download your code and looked at it. The line with convertCoords from it is:
ss << "<" << pos.x << ", " << pos.y << ">\t<" << window.convertCoords(pos, standard).x << ", " << window.convertCoords(pos, standard).y << ">";"
I couldn't figure out how you got:
window.convertCoords(pos, standard).x <=============== your code
- from -
Vector2f convertCoords (const Vector2i &point) const <===== SFML 2.0 documentation
Thanks,
Raptor
-
There's an overload that takes a vector 2i and a view, the 1 argument version uses window's current view.
-
I discovered some things about SFML's fullscreen command via experimentation.
CONFIGURATION AND CODE INFO:
------------------------------------------
Tower PC's monitor = 1680 x 1050 native resolution. Win7's resolution set to that.
Laptop's screen .... = 1280 x 800 native resolution. Vista's resolution set to that.
SFML statement:
App.create(sf::VideoMode(1440, 900, 32), "CRAPS", sf::Style::Fullscreen);
PROGRAM EXECUTION:
----------------------------
Tower PC:
=GOOD= Loading a 1440 x 900 image, the image is expanded to 1680 x 1050 and fits perfectly on the fullscreen.
= BAD = Loading a 1024 x 768 image, the image is NOT expanded and remains at 1024 x 768 on screen.
............. Why doesn't the image get expanded to 1200 x 900 to fill the screen vertically with black bars on the sides?
Laptop:
= BAD = Loading a 1440 x 900 image, the image displays full screen but the image size remains at 1440 x 900. Therefore the right and bottom sides of the image are cut off, since the laptop's screen size is smaller than the image size.
............. IOW, the larger image is not resized down to fit the smaller screen when using the Fullscreen command.
= BAD = Loading a 1024 x 768 image, the image is NOT expanded and remains at 1024 x 768 on screen.
............. Same symptom as on the tower's monitor.
CONCLUSION:
-----------------
I don't see how it's possible to use SFML's "Fullscreen" command to resize one image to fit different sizes and aspect ratios of screens. Am I doing something wrong? If you know why, please let me know.
Thanks,
Raptor
-
What do you mean by using fullscreen command?!
Also, show us the example you used and how were you resizing the image.
Just saying
App.create(sf::VideoMode(1440, 900, 32), "CRAPS", sf::Style::Fullscreen);
simply won't do.
TBH I don't know what you did but nothing will ever resize automagically on itself, ever.
-
What do you mean by using fullscreen command?!
Also, show us the example you used and how were you resizing the image.
Just saying
// Main.cpp
App.create(sf::VideoMode(1440, 900, 32), "CRAPS", sf::Style::Fullscreen);
simply won't do.
TBH I don't know what you did but nothing will ever resize automagically on itself, ever.
Maybe I should have said "Fullscreen Class" instead of Fullscreen command?
Here's the code I'm using:
int _tmain(int argc, _TCHAR* argv[])
{
int SCREEN_WIDTH = 1440;
int SCREEN_HEIGHT = 900;
sf::RenderWindow App;
App.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "CRAPS", sf::Style::Fullscreen);
App.setPosition(sf::Vector2i(0, 0)); //Set topleft corner of window to 0, 0.
// In MainMenu.cpp
MainMenu::eMenuResult MainMenu::show (sf::RenderWindow &App)
{
sf::Texture image;
if (image.loadFromFile ("Images/Table1440x900.png") != true)
{
return EXIT; // EXIT is not a valid return value. <<<<< fix this later >>>>>
}
sf::Sprite sprite (image);
App.draw (sprite);
App.display ();
I replace "Images/Table1440x900.png" with "Images/Menu1024x768.png" when I try the 1024x768 image size.
Hope this is the info you asked for,
Raptor
-
I guess you meant EXIT_FAILURE which is just a macro for 1 anyway.
Do
sprite.setScale(App.getSize().x/image.getSize().x,App.getSize().y/image.getSize().y);
and see if it makes your images of different sizes strech to fill your window and your requirements.
-
Do
sprite.setScale(App.getSize().x/image.getSize().x,App.getSize().y/image.getSize().y);
and see if it makes your images of different sizes strech to fill your window and your requirements.
Hi FRex,
I really appreciate your taking the time to help me out. I'll learn what the code you posted does and try using it. Will post my results.
Thanks,
Raptor
-
Hi FRex,
I really appreciate your taking the time to help me out. I'll learn what the code you posted does and try using it. Will post my results.
FRex,
I inserted your code but nothing happened. The "Menu1024x768.png" image was still displayed as 1024x768 on the Fullscreen display. I found that (float) has to be inserted in the statement and then it works.
sprite.setScale((float)App.getSize().x/(float)image.getSize().x, (float)App.getSize().y/(float)image.getSize().y);
The quality of the image is degraded when the image is scaled larger. Also, the aspect ratio of the image is changed depending on the aspect ratio of the user's screen.
I'll play with setScale somemore. Thanks for letting me know how to use it.
Raptor
-
Yes, the (float) should be there, my mistake.
-
Yes, the (float) should be there, my mistake.
Btw it's imho better to use the 'new' C++ casting functionalities static_cast<type>(var) instead of the old C-ish ones (type)var. ;)
-
Yes, definitely. New style casts make searches quicker and your intentions clear to compiler. I never use c-style casts or function style casts in code that is going to stay(i.e. not quick & dirty temporary test line).
-
Btw it's imho better to use the 'new' C++ casting functionalities static_cast<type>(var) instead of the old C-ish ones (type)var. ;)
Could you post the setScale statement using the new C++ casting functionality you referred to?
Thanks,
Raptor
-
I also thought that using fullscreen mode would distort the image if the aspect ratio of the screen was not the same as the aspect ratio of the image. IOW, I thought it would stretch the image to fill the entire screen even if the aspect ratios didn't match. I just tried a 4:3 aspect image as full screen on my 16:10 monitor and now see that's not the case. SFML displays the 4:3 aspect image with a black bar on the right side so it retains the image's aspect ratio as it should.
Need to correct the paragraph above that I previously posted, for folks who might read it later. What actually happened was that the 4:3 aspect image (1024x768) was not displayed full screen but was displayed at 1024x768 with a black background. This is discussed after I posted the comments quoted above.
Raptor
-
Could you post the setScale statement using the new C++ casting functionality you referred to?
Seriously? :o
sprite.setScale(static_cast<float>(App.getSize().x)/static_cast<float>(image.getSize().x),
static_cast<float>(App.getSize().y)/static_cast<float>(image.getSize().y));
Also read that to see why c-style cast should be avoided : http://www.stroustrup.com/bs_faq2.html#static-cast
-
Could you post the setScale statement using the new C++ casting functionality you referred to?
Seriously? :o
sprite.setScale(static_cast<float>(App.getSize().x)/static_cast<float>(image.getSize().x),
static_cast<float>(App.getSize().y)/static_cast<float>(image.getSize().y));
Also read that to see why c-style cast should be avoided : http://www.stroustrup.com/bs_faq2.html#static-cast
FRex,
You are a good and patient person. Thanks for the answer :).
Raptor