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

Author Topic: Mysterious error when loading an image and use sf::String  (Read 3609 times)

0 Members and 1 Guest are viewing this topic.

JDieskau

  • Newbie
  • *
  • Posts: 6
    • View Profile
Mysterious error when loading an image and use sf::String
« on: April 02, 2009, 02:23:50 pm »
At first, sorry for my bad english. I hope someone understand me.

Here is a little test-code:
Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>

int main( int argc, char **argv )
{
  sf::RenderWindow App;
  sf::String str ( " Test " );

  App.Create( sf::VideoMode::GetDesktopMode(), "Test", sf::Style::Close );

  while ( true ) {
    App.Draw ( str );
   
    App.Display();
    App.Clear();
  }


}

It draws a string in the left upper corner and should look like this:


Allright? Good. Now my problem. I extend the code to this:
Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>

int main( int argc, char **argv )
{
  sf::RenderWindow App;
  sf::Image img;

  if ( !img.LoadFromFile ( "test.png" ) ) {
    return false;
  }

  sf::String str ( " Test " );

  App.Create( sf::VideoMode::GetDesktopMode(), "Test", sf::Style::Close );

  while ( true ) {
    App.Draw ( str );
   
    App.Display();
    App.Clear();
  }
}

Annotation:
Quote
$ file test.png
test.png: PNG image data, 50 x 50, 8-bit/color RGB, non-interlaced


And now it looks like shit:

In my opinion, the code is right. Whats wrong here?
Btw. if I instantiate the sf::String first, then it looks like picture 1 - all right. But something goes definitive wrong. Any idea?


I use Gentoo Linux. My tested sfml versions are: 1.4, trunk svn und brunch 2.0 svn

EDIT 1: With the svn version i get this error message:
Quote
Failed to create image, its internal size is too high (300x230)

Its an texturesize ore somesthing like that? OpenGL? But 300x230? I have a NVidia GeForce 9600M GT and the newest stable driver -> 180.29

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Mysterious error when loading an image and use sf::String
« Reply #1 on: April 02, 2009, 03:04:38 pm »
What happens if your image's dimensions are powers of two? Some graphics card (mostly olders) don't support dimensions which aren't powers of two.

I'm not sure about this, but does it solve your problem when you first create the window and then load the image? Maybe that ordering is important. I guess Laurent can say more about that.

JDieskau

  • Newbie
  • *
  • Posts: 6
    • View Profile
Mysterious error when loading an image and use sf::String
« Reply #2 on: April 02, 2009, 03:28:21 pm »
Quote from: "Tank"
What happens if your image's dimensions are powers of two? Some graphics card (mostly olders) don't support dimensions which aren't powers of two.

I'm not sure about this, but does it solve your problem when you first create the window and then load the image? Maybe that ordering is important. I guess Laurent can say more about that.

I created a 64x64px picture and its the same error. BUT you are right, I have to use the sf::Window::Create first!

But in my real project it doesnt help :(
I have a private Variable "sf::RenderWindow* App" in a Class called "CGame". The first what i do in the constructor is this:
Code: [Select]
 App = new sf::RenderWindow;
  App->Create( settings::getVideo(), "Game", sf::Style::Close, settings::getWindowSettings() );

And in main() the first is to create an object of "CGame". So whats wrong now?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Mysterious error when loading an image and use sf::String
« Reply #3 on: April 02, 2009, 03:48:02 pm »
What do settings::getVideo() and settings::getWindowSettings()?

And why are you using a pointer at all? You can declare the member variable App as sf::RenderWindow App. Then your constructor could look like:

Code: [Select]

CGame::CGame() :
  App( sf::VideoMode( ... ), "Blah" , ... )
{
  ...
}


Are you sure the window gets opened? You can check it with App.IsOpened(). Maybe either the video mode parameter or window settings parameter is wrong.

JDieskau

  • Newbie
  • *
  • Posts: 6
    • View Profile
Mysterious error when loading an image and use sf::String
« Reply #4 on: April 02, 2009, 04:13:13 pm »
Quote from: "Tank"
What do settings::getVideo() and settings::getWindowSettings()?

And why are you using a pointer at all? You can declare the member variable App as sf::RenderWindow App. Then your constructor could look like:

Code: [Select]

CGame::CGame() :
  App( sf::VideoMode( ... ), "Blah" , ... )
{
  ...
}


Are you sure the window gets opened? You can check it with App.IsOpened(). Maybe either the video mode parameter or window settings parameter is wrong.

Thank you. Now its working!

 

anything