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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - chris67

Pages: [1]
1
Graphics / Huge problem with SFML
« on: January 06, 2010, 08:50:57 pm »
This is a total game breaker for me unless I am missing something huge here.

The problem is when I add GetEvent(Event) in my code it slows or even STOPS my program when I move the mouse around.

I display the fps and even added a counter to increment each time the program loops and they both stop dead when I move the mouse.

I have been puzzling over this for quite a while and I cannot find anything on the forum about it.

Here is my code, someone else please run it and see if you get the same results:

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
    sf::Font MyFont;
    sf::String fps;
    sf::String counter;
    char buffer[200];
    int num = 0;

    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

    if (!MyFont.LoadFromFile("font/small/XPAIDERP.TTF", 8))
        return EXIT_FAILURE;

    fps.SetFont(MyFont);
    fps.SetSize(8);
    fps.SetPosition(100.f, 100.f);

    counter.SetFont(MyFont);
    counter.SetSize(8);
    counter.SetPosition(100.f, 200.f);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        App.Clear();

        sprintf( buffer, "FPS = %f", 100.f / App.GetFrameTime() );
        fps.SetText( buffer );
        App.Draw( fps );

        sprintf( buffer, "COUNTER = %d", num );
        counter.SetText( buffer );
        App.Draw( counter );

        App.Display();

        num++;
    }

    return EXIT_SUCCESS;
}


I move the mouse around and both the counter and the fps freeze. This can only mean the program itself is freezing. If I comment out while (App.GetEvent(Event)) then everything goes smoothly and I can move the mouse around with no freezing.

System:

WindowsXP service pack 3
DirectX 9.0c
AMD athlon 2.21 GHZ
2 GB RAM

Using Code::blocks IDE with MingW

2
Graphics / Re-using sf::Image?
« on: January 06, 2010, 02:17:59 am »
Is it safe to use the same sf::Image variable for more then one bitmap?

If I do this for instance:

Code: [Select]

sf::Image bitmap;
sf::Sprite sprite;

bitmap.LoadFromFile( "bitmap1.bmp" );

sprite.SetImage( bitmap );

App.Draw( sprite );

// and then do this

bitmap.LoadFromFile( "bitmap2.bmp" );

sprite.SetImage( bitmap ); // do I need to do this again?

App.Draw( sprite );


Is this safe or will I get a memory leak somewhere?

3
Graphics / Blurry text
« on: December 30, 2009, 12:33:49 am »
I am using 640 x 480 x 32 bit mode and so I use small .ttf fonts, but when I blit them to the screen there is some kind of automatic AA done to them which makes them blurry and ruins the readability.

For example, at 12 pt it looks like this ( enlarged 3x ):



I tried to use this command to turn off blending:

SetBlendMode( sf::Blend::None );

But when I do that I get this ( enlarged 3x ):



Any help would be appreciated.

Here is my code

Code: [Select]


FontClass::FontClass( char *filename, int s )
{
    size = s;

    if( !( font.LoadFromFile( filename, size ) ) )
    {
        char errormsg[200];
        sprintf( errormsg, "Failed to load - %s", filename );
        DisplayError( errormsg );
    }
}

FontClass::~FontClass()
{
}

// function to draw the font
void FontClass::DrawFont( char *text, int x, int y, int cx, int cy )
{
    sf::String Txt( text, font, size );

    Txt.SetPosition( float ( x ), float( y ) );

    App.Draw( Txt );
}

Pages: [1]
anything