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

Author Topic: dummy question on sf::Image::CopyScreen  (Read 9450 times)

0 Members and 1 Guest are viewing this topic.

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« on: November 21, 2008, 04:19:09 pm »
Hi,

after discovering sf::Image::CopyScreen I thought I could draw some text on the screen, invoke Image::CopyScreen to copy the relevant part of the screen to an image and after that to set a corresponding sprite.

Code: [Select]

sf::String Letter("B", Arial100, 100) ;
sf::Image Image1 ;
sf::Sprite Sprite1;

Letter.SetPosition( 0, 0 ) ;
Screen.Draw( Letter) ;
Image1.CopyScreen( Screen, sf::IntRect(0, 0, 100, 100) ) ;
Sprite1.SetImage( Image1 );


But this results in an 'empty' image/sprite. Thus, something must be wrong with my thinking Image::CopyScreen works.

Please, can someone enlighten me :-)

Thanx - Sven

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #1 on: November 21, 2008, 04:37:09 pm »
It should work. Did you try saving the image to a file ?
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #2 on: November 21, 2008, 04:56:01 pm »
Just did a SaveToFile().

Interestingly, the image/sprite is no longer empty but shows a
nice stripe pattern ;-)

BTW: SaveToFile() saves in what format? IrfanView accepts it as *.bmp...

ciao - Sven

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #3 on: November 21, 2008, 05:06:12 pm »
SaveToFile deduces the format from the filename extension. So you won't get anything if you don't specify a valid one... ;)

One more test : you can insert a Screen.Display() just before the call to CopyScreen.
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #4 on: November 21, 2008, 05:44:44 pm »
Hi,

I inserted a Screen.Display() before CopyScreen, this did not change anything. The saved image looks like this:


-Sven-

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #5 on: November 21, 2008, 07:21:48 pm »
Ok, I'll check this as soon as possible.
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #6 on: November 21, 2008, 09:13:27 pm »
Hi Laurent,

I did a bit more testing...

Code: [Select]

sf::String Letter("B", Arial100, 100) ;
sf::Image Image1, Image2 ;
sf::Sprite Sprite1, Sprite2;

Letter.SetPosition( 0, 0 ) ;
Screen.Draw( Letter) ;
Screen.Display() ;
Image1.CopyScreen( Screen, sf::IntRect(0, 0, 100, 100) ) ; // does not the copy
Image2.LoadFromFile( "testimage.bmp" ) ; // runs okay due to your fix on image loading and creation - thanks again


But:

Code: [Select]

sf::String Letter("B", Arial100, 100) ;
sf::Image Image1, Image2 ;
sf::Sprite Sprite1, Sprite2;

Letter.SetPosition( 0, 0 ) ;
Screen.Draw( Letter) ;
Screen.Display() ;
Image1.CopyScreen( Screen, sf::IntRect(0, 0, 100, 100) ) ; // does not the copy, but results in funny stripes
Image1.SaveToFile( "test.bmp" ) ; // saves the funny stripes to disk
Image2.LoadFromFile( "testimage.bmp" ) ; // crashes Windows XP


That means: a LoadFromFile is pretty okay,  but a previous SaveToFile causes LoadFromFile to crash Windows. Only a hard reset reanimates Windows. The crash results in a pixel mess at the top of the display.

-Sven-

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #7 on: November 24, 2008, 07:45:22 pm »
Ok, two things :
- I fixed the crash happening after a call to SaveToFile
- CopyScreen actually works, except that the source image is flipped vertically; that's why you don't see your B.

I'll definitely have to find a good solution (not just workarounds) for this flipped coordinates issue, as it impacts multiple parts of the code.
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #8 on: November 26, 2008, 03:21:56 pm »
Quote from: "Laurent"
Ok, two things :
- I fixed the crash happening after a call to SaveToFile
- CopyScreen actually works, except that the source image is flipped vertically; that's why you don't see your B.

I'll definitely have to find a good solution (not just workarounds) for this flipped coordinates issue, as it impacts multiple parts of the code.


Hi Laurent,

thanks a lot for your help. I verified that CopyScreen works and LoadFromFile no longer crashes after a call to SaveToFile.

Unfortunately, I found some other problems...

Code: [Select]
Image1.CopyScreen( Screen, sf::IntRect(x1, y1, x2, y2) ) ;
Image1.SaveToFile( "test1.jpg" ) ;


works if and only if (x2-x1) <= 1024. Otherwise, SaveToFile crashes.

And the saved files are distorted unless the image-width is a power of 2, e.g. x2-x1 = 64 = 2^6 results in a correct saved image (besides y-flipping), image width of 63 or 65 pixel gives strange results, image width of 128 is okay and so on...

HTH - Sven (thanx again for your invaluable help)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #9 on: November 26, 2008, 03:32:54 pm »
Quote
works if and only if (x2-x1) <= 1024. Otherwise, SaveToFile crashes.

1024 must be the maximum texture size supported by your graphics card ;)

Quote
And the saved files are distorted unless the image-width is a power of 2, e.g. x2-x1 = 64 = 2^6 results in a correct saved image (besides y-flipping), image width of 63 or 65 pixel gives strange results, image width of 128 is okay and so on...

Can you upload an example of such a distorted image ?
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #10 on: November 26, 2008, 04:18:15 pm »
Quote from: "Laurent"
Quote
works if and only if (x2-x1) <= 1024. Otherwise, SaveToFile crashes.

1024 must be the maximum texture size supported by your graphics card ;)

Quote
And the saved files are distorted unless the image-width is a power of 2, e.g. x2-x1 = 64 = 2^6 results in a correct saved image (besides y-flipping), image width of 63 or 65 pixel gives strange results, image width of 128 is okay and so on...

Can you upload an example of such a distorted image ?


Okay, max texture size... I c :-)

Now to the relevant images. On screen everything is fine. The following images are the saved ones.

129 x 128 px:


128 x 128 px: that's visible on the screen


127 x 128 px:


126 x 128 px:


Another example:

127 x 110 px:


128 x 110 px: that's on the screen




Looks somehow systematic to me ;-)

Yours - Sven

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #11 on: November 26, 2008, 04:36:08 pm »
Ok I see. I'm going to check this, thanks for your help :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #12 on: November 26, 2008, 05:57:24 pm »
It's fixed now.
Laurent Gomila - SFML developer

SvenB

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • http://www.psych.uni-halle.de/sven/
dummy question on sf::Image::CopyScreen
« Reply #13 on: November 26, 2008, 10:07:11 pm »
Thanks a lot! Great.

Now I can easily flip.x and flip.y strings, just draw the string on screen,
CopyScreen the string to an Image, make it a sprite and flip the sprite.
You made my day.

Thanx again.

-Sven-

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dummy question on sf::Image::CopyScreen
« Reply #14 on: November 26, 2008, 10:19:52 pm »
Sorry that you still have to use such hack, I promise that true render-to-image will be implemented soon :D

By the way, why do you need to pre-render text ? Is it a performance issue ?
Laurent Gomila - SFML developer

 

anything