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

Author Topic: Problems with Display  (Read 3512 times)

0 Members and 2 Guests are viewing this topic.

wickedgenius

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problems with Display
« on: September 27, 2009, 11:42:00 pm »
I'm having problems with the Display function of RenderWindow.

Every other call seems to display something strange while the other call displays what it should. Is there anything I might be doing that would cause this?

This is my main loop, if anything else is needed then i can post it but otherwise there is a fair amount of code:

Code: [Select]
while( 1 )
{

sf::Event Event;
while( App.GetEvent( Event ) )
{

if( Event.Type == sf::Event::Closed )
{

App.Clear();
App.Close();
defGrid.XYGridPointers.clear();
return 0;

}

}

if( defGrid.HasChanged() )
{

App.Clear( sf::Color( 0, 255, 0 ) );
defGrid.Draw( App, MyFont, iniFile );

}

App.Display();

}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems with Display
« Reply #1 on: September 28, 2009, 07:46:53 am »
You can't call Display if you haven't drawn anything.
Laurent Gomila - SFML developer

wickedgenius

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problems with Display
« Reply #2 on: September 28, 2009, 09:32:02 am »
I also get it for the following code which does draw something each frame:

Code: [Select]
sf::Shape Rect = sf::Shape::Rectangle( 0, 650, 50, 675, sf::Color( 255, 0, 0 ) );

while( 1 )
{

//App.Clear( iniFile.GetColorSfBg() );

sf::Event Event;
while( App.GetEvent( Event ) )
{

if( Event.Type == sf::Event::Closed )
{

App.Clear();
App.Close();
defGrid.XYGridPointers.clear();
return 0;

}

}

float FrameRate = 1.f / App.GetFrameTime();
std::stringstream FPSString;
FPSString << (int)FrameRate;

App.Draw( Rect );

sf::String Text( FPSString.str(), MyFont, iniFile.GetFontSize() );
Text.SetPosition( 0, 650 );
Text.SetColor( iniFile.GetColorSfFg() );
App.Draw( Text );

if( defGrid.HasChanged() )
{

App.Clear( sf::Color( 0, 255, 0 ) );
defGrid.Draw( App, MyFont, iniFile );

}

App.Display();

}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems with Display
« Reply #3 on: September 28, 2009, 10:26:15 am »
In this one you don't always clear the window before rendering a new frame. You should ;)
Laurent Gomila - SFML developer

wickedgenius

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problems with Display
« Reply #4 on: September 28, 2009, 11:09:17 am »
The thing is I want to cut down on the amount of rendering of a particular part of the screen. A large section of it is made up of sf::Strings which have only a single character so it runs quite slowly when rendering it (about 8 FPS) but if I do what I do now it is faster (700 FPS+, I have managed to have it work but it's different each time the app is run).

So is there a way to take an area of the screen and redisplay it each frame without having to redraw every string?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems with Display
« Reply #5 on: September 28, 2009, 11:16:22 am »
Quote
So is there a way to take an area of the screen and redisplay it each frame without having to redraw every string?

Not in SFML 1.x. SFML 2 will provide solutions to this kind of problems.

Quote
A large section of it is made up of sf::Strings which have only a single character so it runs quite slowly when rendering it (about 8 FPS)

What kind of stuff are you displaying? :)
Maybe we can concentrate on this thing, and try to optimize it.
Laurent Gomila - SFML developer

wickedgenius

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problems with Display
« Reply #6 on: September 28, 2009, 01:29:01 pm »
What I'm trying to achieve is a roguelike made in SFML so that eventualy it can easily use sprites instead and also because it's a hell of a lot easier than a curses library.

So what I'm doing is displaying a string for each tile of the roguelike and each of these tiles is stored inside a Tile class with tile classes stored in the RogueGrid class called defGrid. (In fact I've just had a thought that may help to optimize it as I think I may be making a new string in every tile while I could just use one for the RogueGrid and change it for each tile after drawing it.)

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Problems with Display
« Reply #7 on: September 28, 2009, 02:20:24 pm »
Quote from: "Laurent"
Quote
So is there a way to take an area of the screen and redisplay it each frame without having to redraw every string?

Not in SFML 1.x. SFML 2 will provide solutions to this kind of problems.

By using render-to-image or another solution?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problems with Display
« Reply #8 on: September 28, 2009, 02:24:28 pm »
Quote
By using render-to-image or another solution?

This is the first solution.
The other one is to rely on batching for performances and draw everything every frame :)
Laurent Gomila - SFML developer

wickedgenius

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problems with Display
« Reply #9 on: September 28, 2009, 10:07:11 pm »
Quote from: "Tank"
Quote from: "Laurent"
Quote
So is there a way to take an area of the screen and redisplay it each frame without having to redraw every string?

Not in SFML 1.x. SFML 2 will provide solutions to this kind of problems.

By using render-to-image or another solution?


Done, and it works and gives me 300 FPS (not as good as before but not a problem).