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 - eXpl0it3r

Pages: 1 ... 4 5 [6] 7
76
Audio / Examples that use (self built) OpenAL fail to build
« on: October 27, 2012, 11:31:36 pm »
So I've been try to build a native 64bit version of SFML with MinGW-w64, but since SFML doesn't ship with 64bit external libraries, I had to build them on my own.
Everything seems to work quite well (after editing the CMake macro file) except when trying to build the examples that use the static audio module of SFML it errors out with the following message:

..\..\lib\libsfml-audio-s.a(SoundBuffer.cpp.obj):SoundBuffer.cpp:(.text+0x65): undefined reference to `__imp_alBufferData'
..\..\lib\libsfml-audio-s.a(SoundBuffer.cpp.obj):SoundBuffer.cpp:(.text+0x68a): undefined reference to `__imp_alDeleteBuffers'
..\..\lib\libsfml-audio-s.a(SoundBuffer.cpp.obj):SoundBuffer.cpp:(.text+0xcf3): undefined reference to `__imp_alDeleteBuffers'
c:/dev/mingw64-rubenvb/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: ..\..\lib\libsfml-audio-s.a(SoundBuffer.cpp.obj): bad reloc address 0x0 in section `.pdata'
c:/dev/mingw64-rubenvb/bin/../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [examples/pong/pong.exe] Error 1
mingw32-make[1]: *** [examples/pong/CMakeFiles/pong.dir/all] Error 2
mingw32-make: *** [all] Error 2
 

Since I've build OpenAL myself I'm not sure if I've used the correct version or setup everything right and thus I'm not only asking how to resolve this issue, but also if there are any special steps required when building SFML?

77
General discussions / Unofficial Nightly Builds
« on: October 27, 2012, 12:44:33 am »
If you're new to SFML or basically building any library, I strongly advise you to first learn how to use your development environment and how to build libraries on your own, since for a developer it's crucial to know how libraries work and how they get build. For that matter you can read the official tutorial for SFML here.

For the other ones these nightly builds should keep you up-to-date.

The builds are packed with 7zip and contain all the different possibilities on how to build SFML, Thor and CSFML.
Since the libraries have for mostly all combination a unique name they are all placed directly in the lib directory. The only combination that would overwrite existing libraries, are the ones with the runtime library linked statically, thus they got placed into a separate sub-directory lib/static-std.
The DLLs can be found as usual in the bin directory.
The examples have been linked statically to SFML and statically to the runtime library.
The archives also contain the full and up-to-date documentation.

SFML Dev
Check out the post about our Continuous Integration system that constantly provides uptodate builds!

CSFML Dev

Latest [ee9b927dec]
Earlier
Thor Dev

Latest [84f4821e49]
Earlier
SFGUI Dev

Latest [6f4a009337]
Earlier
If you got any questions, comments, suggestions, etc. feel free to leave them in this thread or contact me directly via PM/email. :)

78
So I was creating a small batch file to compile all the different variants of SFML 2 with Visual Studio 11 and everything worked fine until I checked the 'build examples' box.
The examples build fine for the static and dynamic libraries which use the dynamic runtime libraries build fine, but as soon as you try to build the examples with the static runtime library you get many unresolved symbols and other errors, here the full list for the OpenGL example:
Linking CXX executable opengl-d.exe
sfml-graphics-s-d.lib(ftbase.obj) : warning LNK4217: locally defined symbol "_strrchr" imported in function _raccess_make_file_name
sfml-graphics-s-d.lib(type1.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(truetype.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(ftlzw.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(ftbase.obj) : warning LNK4217: locally defined symbol "_memmove" imported in function _FT_GlyphLoader_CheckPoints
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(pshinter.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_fwrite" imported in function _empty_output_buffer
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_free" imported in function _empty_mem_output_buffer
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4049: locally defined symbol"_free" imported
sfml-graphics-s-d.lib(jmemnobs.obj) : warning LNK4049: locally defined symbol"_free" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_malloc" imported in function _empty_mem_output_buffer
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4049: locally defined symbol"_malloc" imported
sfml-graphics-s-d.lib(jmemnobs.obj) : warning LNK4049: locally defined symbol"_malloc" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_ferror" imported in function _term_destination
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_fflush" imported in function _term_destination
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "_exit" imported in function _error_exit
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "___iob_func" imported in function _output_message
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "_sprintf" imported in function _format_message
sfml-graphics-s-d.lib(bdf.obj) : warning LNK4049: locally defined symbol "_sprintf" imported
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_realloc" imported in function _ft_realloc
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fclose" imported in function _ft_ansi_stream_close
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fread" imported in function _ft_ansi_stream_io
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fseek" imported in function _ft_ansi_stream_io
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_ftell" imported in function _FT_Stream_Open
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fopen" imported in function _FT_Stream_Open
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4217: locally defined symbol "_memchr" imported in function _tt_face_find_bdf_prop
sfml-graphics-s-d.lib(cff.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(type1.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4217: locally defined symbol "_strncmp" imported in function _tt_face_find_bdf_prop
sfml-graphics-s-d.lib(psaux.obj) : warning LNK4217: locally defined symbol "_strncmp" imported in function _afm_parser_parse
sfml-graphics-s-d.lib(type42.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_strncmp" imported
sfml-graphics-s-d.lib(type42.obj) : warning LNK4217: locally defined symbol "_atol" imported in function _t42_get_name_index
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_atol" imported
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__longjmp" referenced in function "_ft_validator_error".
sfml-graphics-s-d.lib(smooth.obj) : error LNK2001: unresolved external symbol "__imp__longjmp".
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__strncpy" referenced in function "_raccess_make_file_name".
sfml-graphics-s-d.lib(type1.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__qsort" referenced in function "_FT_Raccess_Get_DataOffsets".
sfml-graphics-s-d.lib(bdf.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(psmodule.obj) : error LNK2001: Nicht aufgelöstes externesSymbol "__imp__qsort".
sfml-graphics-s-d.lib(psaux.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(jerror.obj) : error LNK2019: unresolved external symbol "__imp__fprintf" referenced in function "_output_message".
sfml-graphics-s-d.lib(truetype.obj) : error LNK2019: unresolved external symbol "__imp__strstr" referenced in function "_tt_check_trickyness_family".
sfml-graphics-s-d.lib(jmemmgr.obj) : error LNK2019: unresolved external symbol "__imp__sscanf" referenced in function "_jinit_memory_mgr".
sfml-graphics-s-d.lib(jmemmgr.obj) : error LNK2019: unresolved external symbol "__imp__getenv" referenced in function "_jinit_memory_mgr".
opengl-d.exe : fatal error LNK1120: 7 unresolved external symbols.
LINK Pass 1 failed. with 2

The errors look quite similar for the other examples that don't build which are: opengl, pong, shader and win32.
I then even tried the VS10 compiler of which I know that it build fine in the past, so it's not a VS11 issue.
For me it seems like the external libraries (OpenAL, etc) have problems with the statically/build-in runtime library.

Any ideas?

79
SFML projects / eXpl0it3r's Examples
« on: October 23, 2012, 04:45:16 pm »
Those who are following me on GitHub might have already noticed my Examples repository, for all the others (and the first ones too of course), I'm making this forum post.

Every now and then I help out some people or goof around with some ideas or code pieces and sometimes I end up with a small example that kind of looks cool, but I don't really have a purpose for it. So instead of just letting it rot somewhere on my harddisk, I thought it could be a inspiring thing to upload them to GitHub. But just reading code mostly isn't that interesting/inspiring thus I'll share here also some screenshots. :)

All the examples related to SFML can be found in the SFML directory. Keep in mind that the code is provided as-is and isn't always suited for final products, since I didn't spend much time thinking about performance or nice code design decisions. ;)

Fading Dots
This was originally created as a test for this thread (or was it this one?), but since I kind of liked the result I adjusted a few things and uploaded it.



Flashlight
Out of nowhere came suddenly all those requests (starting with this one) for subjective blending and I think, I could help a few people with my example on how to achieve what they wanted.



Hue Shift
Although I can't find the original SFML thread about this, I found the StackOverflow question which was iirc created before the forum thread. This effect can definitely give a nice ambiance, but it probably could need some retouching.
Since the picture do not tell much: Starting off with one color the example automatically iterates through the whole RGB color spectrum in a smooth way.



Lightning
I had once read a tutorial in connection with SFML on how to create some nice 'laser' effect. Unfortunatly I don't remember which blog/site this was on, because he was using some texture moving which made everything look even better. While doing a search to possible find that tutorial again, I found another similar piece of code on the forum, adapted it for SFML 2 and made a nicer class out of it.



Road
I'm not sure if there ever existed a forum post or if the whole conversation happend on IRC, but someone wanted to make a 'scrolling' road and since I really liked that idea, I went ahead and implemented an example. The code here is particularly not that nice, so keep that in mind when adapting it. ;)



Simple AABB
Every month there's at least one question on simple collision detection testing the last 'bigger' one with in this forum thread, which lead to this example. I've even implemented some very simple physics, which will fail in most situations, but you can at least move around and jump. :)



Mixing SoundBuffers
The other day in #learnprogramming on freenode someone was trying to implement a way to mix two audio files without actually playing them back. I wondered how something like that would work with SFML and thus went ahead an wrote a small example. A quick Google search on audio sample mixing brought me to this site and lead me to the current implementation.


Everything is under the zlib/png license and you can use it and reference it in whatever way you want. :)

80
SFML wiki / Major Wiki Link Breakage
« on: October 18, 2012, 04:56:06 pm »
So since GitHub has changed the way they handle page titles and names, we no longer could use the old way of having a short and handy name while keeping the title descriptive.
Since the problem has been around for quite a while and Laurent has is hands full of work, I decided to change the rules and adapt all current wiki pages.
But as nice as it now looks, the change comes with a big downside. Every link that has ever been made to mostly all wiki pages now lead nowhere... :-\

If you're a maintainer of some wiki-forum post, please make sure to update the wiki link. Also if you stumble upon some wiki link in one of your post, please make sure to edit it.

I hope nobody will kill me for that change, but it was necessary to prevent ugly entanglements between different naming conventions and confusions. ;)

As a side note: There are quite a few red links from links that where taken over to the new wiki, but have never been created/updated. If you have some old tutorial/source code/etc in the old wiki but not in the new one, think about take some time to convert it. Or if you have some free time at your hands, you may convert some pages if you want to. ;

81
SFML projects / SFMLUploads.org - Relaunch!
« on: October 08, 2012, 02:51:29 pm »
After quite a few ups and even more downs SFMLUploads is finally back online!

SFMLUploads.org was originally created by the user Haikarainen back in May 2011 but due to server issues the project had experienced some hiccups in the early days and then went offline in July 2012. As quite a few things have been uploaded to that site and linked to in this forum, I felt it was wrong to lead the project drop dead, thus I contacted Haikarainen and convinced him to let me host and maintain the website. So here we are with the relaunch of SFMLUploads!

All the files and user accounts have been successfully transferred over to the new host, thus you'll be able to log into your old account again to get access to your files.
If you don't remember your password you can contact me and I'll give you the opportunity to re-register.


SFMLUploads is aimed at developers using the SFML library, and it's main purpose is to serve those users with bandwidth for:
  • Project archives, allowed extensions are: .rar, .zip, .tar, .tar.gz, .tgz, .deb, .rpm, .7z, .xz, and .ace.
  • Code-snippets, syntax-highlighted code with support for 100+ languages, "fork"-able, meaning users can create other versions of it. Useful with debugging etc. Kind of like Pastebin.
  • Screenshots/images, allowed extensions are .jpg, .jpeg and .png. Primarily for screenshots, but other picture are allowed as well.
The main rule is: It HAS to have something to do with SFML, either if it's for a forum post where you seek help for debugging a problem related to/which uses SFML, or if it's download links for your awesome game on your personal blog or something, etc. You can read the full terms here; they also apply to the existing users and where introduced to not only protect me but also you.
Keep in mind that this service is not for project presentations, like the official wiki for SFML is, but it's a place to have your binaries, images, code fragments, etc for your project in a nice and easy manageable way.

If you notice any problems or have suggestions feel free to contact me or write them here for discussion.

I hope you like it - signup and enjoy! :)

Known Issues
  • The Facebook like button has been temporarily removed, since it caused the website to load extremely slow.

PS: This service is 100% free, if you feel like donating for the hosting cost then you can do this here. Thanks!

82
General discussions / 1.6 symbols in 2.0 API documentation
« on: August 23, 2012, 12:08:17 pm »
I've quickly searched through the header files and found a few symbols with the old naming conventions, so I thought I might as well share them... ;)

Sound.hpp:123 GetBuffer -> getBuffer
CircleShape.hpp:99 GetPointCount -> getPointCount
ConvexShape.hpp:85 GetPointCount -> getPointCount
ConvexShape.hpp:98 GetPointCount -> getPointCount
ConvexShape.hpp:81 SetPointCount -> setPointCount
RectangleShape.hpp:86 GetPointCount -> getPointCount
Shape.hpp:204 GetPointCount -> getPointCount
VertexArray.hpp:78 GetVertexCount -> getVertexCount
VertexArray.hpp:94 GetVertexCount -> getVertexCount
TcpSocket.hpp:230 GetRemotePort -> getRemotePort
Http.hpp:343 SetHost -> setHost
Http.hpp:376 SetHost -> setHost
SoundRecorder.hpp:218 IsAvailable -> isAvailable
VideoMode.hpp:204 IsValid -> isValid
 
The example in the Transformable.hpp could maybe also be adapted to follow the camelCase scheme. :)

83
SFML projects / Jumpy - A Doodle Jump clone
« on: July 26, 2012, 01:25:18 am »
Jumpy
A Doodle Jump clone



Description
Jumpy is a clone of the well-known Doodle Jump game created by Lima Sky and originally developed for iOS but in the meantime also ported to Android.
The first version of Jumpy, back then it had the name 'Doodle Jumpy', was released for the 19th SCC (SFML Community Contest) of the German speaking SFML community. Within this one year my skills with C++ and SFML have greatly advanced and SFML itself has undergone big changes, which led me to refactor the game and I've now come to a state where the new version is fully playable. In the future I'll keep refactoring and cleaning up the codebase, perhaps even adding new features.

Download & Source
License & Credits
This game is using the same license as SFML, namely zlib license.
With the refactoring I've introduced the SmallGameEngine into the game, it's heavily based on the 'Managing Game States in C++' tutorial by Anthony Lewis, so a big thanks to him for that tutorial.
And obviously the biggest thank you goes to Laurent, for his awesomeness in constantly developing and maintaining one of the best C++ libraries. ;D

84
SFML website / Search/Database problem
« on: July 24, 2012, 06:33:42 pm »
I've now run twice into this database error with the search function and I guess it could happen even more often if I'd need to use the search function more (which I probably should have ;D).



Do you know the reason for this and/or how it could get fixed?


(A side note isn't 128kb individual file size a bit too limiting, e.g. couldn't add the image as attachment....)

85
On IRC DevilWithin just pointed out a bug in SFML with the Windows implementation.
If you're checking for the MouseMoved event and then press the ALT key, the MouseMoved event will not get triggered anymore until you either press any alpha-numberic, the ALT or the ESC key or you click somewhere.

The bug probably occurs because the ALT key normally gets directed to the menu which doesn't exist in SFML. Visually you can't see a difference but from the message queuing the Window somehow loses the 'focus'.

Here's a minimal complete example that will reproduce the problem:

#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "MouseMoved Bug");

        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::MouseMoved)
                                std::cout << event.mouseMove.x << "," << event.mouseMove.y << std::endl;
                }
 
                window.clear();
                window.display();
        }
}

On the console you'll see the mouse position received via the event. Now as soon as you press ALT the event won't get triggered and there will be no fruther updates on the console.

I'm not quite sure if this is really related or if the bug is triggered through something completly diffrent, but here's a link to a code example that shows how to disable the ALT key interaction with window menu.

86
SFML wiki / [Wiki] Using sf::View
« on: June 23, 2012, 12:36:18 pm »
In the past I've had problems understanding how sf::View really works. A few weeks ago I sat down and started to experiment with it and ended up writing a tutorial or informational article on my blog.
To share the tutorial even more and keep some order I've now also converted my post to a wiki entry on GitHub.

Using sf::View

The tutorial covers:
  • What can sf::View do?
  • How does sf::View work?
  • The source rectangle
  • The size and the constructor
  • The viewport rectangle
  • The convertCoords(…) function
  • Complete demonstration

Everything is illustrated with some images and the final demonstration gives you something you can directly temper with.

I hope it will be usefull for some of you. :)

If you have any questions/suggestions, just answer to this thread and feel free to edit the wiki post if you find any mistakes!

87
SFML wiki / [Wiki] How to change your cursor
« on: June 21, 2012, 04:54:03 pm »
I've added the 'How to change your cursor' tutorial to the GitHub wiki.

@Laurent: Can you change the title? I don't understand how to do it. My first '# Title' doesn't show up. :-\

It's partially based on the old tutorial (probably wirtten by TechRogue). But since the Windows code wasn't working for 64bit platform, I had to make small changes. Additionally I've restructered the class a bit.
I've also expanded the tutorial with the explenation on how to use only SFML functions to get your own cursor.
And finally I've added a demonstration that shows how both technique can be used.

Now the OS specific cursor change has been tested on Windows 7 64bit but at the moment I can't test it for the Linux enviroment. Could someone else try it and if it's not working try to find a workaround?

For the Mac platform I've no idea how to change things. Has anyone some experience in that section and maybe able to add it to the wiki? :)

I hope it will help some of you and feel free to correct my text/code.

Note: It's only for SFML 2!

88
Graphics / Clearing only a part of a sf::RenderTexture
« on: April 23, 2012, 06:21:42 pm »
I was working with a sf::RenderTexture but on which I'd draw diffrent stuff. Now at the beginning the rendertexture gets clear with a fully transparent color thus when exctracting the texture later it will only show something at the place I've drawn something.
The problem is now when I want to remove a drawn square I wont' be able to do this, since I can't clear only a specific area and thus have to clear the whole rendertexture and draw everything again.
If I'd use a non transparent background color it would be easy, I'd just draw a shape over the section I want to remove but you obviously can't draw a transparent shape over something, because it will just shine through.

Am I missing a function here or any other possibilty that doesn't involve direct OpenGL calls or clearing the whole rendertexture?

If not, consider this a feature request... :)

89
I just got this idea, although I'm not sure if it could get annoying or if it's even possible to implement (in a simple way) but I write it down anyway.

When ever some one writes down the class name of a SFML class the forum should automatically link the class to the documentation.
For the class name I would suggest that only names in the form of sf::ClassName get recognized and if they're not in a code block (or other blocks).

For the linking I could think of two diffrent ways:
  • The entry gets 'postprocessed' and with that the sf::ClassName get surrounded with the specific link.
  • Before the text is sent to the user the sf::ClassName get linked to the documentation.
Additionally one could also add the tt-block to let it stand out more.

The question now is which version of SFML to link to. I'd go for SFML 2 (at least as soon as it gets released).

I think it would greatly help specially for the new users to discover the documentation.

90
System / [SFML 2.0] sf::Thread doesn't display sf::Text correctly
« on: January 25, 2012, 07:37:02 pm »
At the moment I'm experimenting with sf::Thread but I get some problems with global sf::Text variables and I'm not sure if SFML is messing something up or my lack of knowledge.

I choose to use the member function version for thread creation and setup three files as an example.

What I basicly want to do is display how each thread is running.
So the code seems in my opinion okay and using a sf::Mutex for the mUPS doesn't change anything.
The problem now is, that only some random numbers get displayed on the window altough the std::cout looks okay.
When further tempering with the text output I noticed that:
1) When setting the text outside of the Draw() function it doesn't get displayed at all (I set it at the intitializastion).
2) Using the mFPS which is declared outside of the Draw function and assign some numbers all the '0' don't get displayed.
3) When using a sf::Text local to the thread it gets displayed without problems.
4) It seems everything works fine with a non-member function without argument.

What I ask myself now, can't I use external sf::Text? If not how would I share text between threads? Or better how would a use threads to draw stuff?

main.cpp
#include "Task.hpp"

int main(int argc, char **argv)
{
        Task test;
       
        test.Run();
   
        return EXIT_SUCCESS;
}
Task.hpp
#ifndef TASK_HPP
#define TASK_HPP

#include <SFML/Graphics.hpp>

class Task
{
public:
        Task();
        ~Task();

        void Draw();
        void Update();

        void Run();

private:
        sf::Text mFPS;
        sf::Text mUPS;
        bool mRun;
        sf::Mutex mLocker;
        sf::Font mFont;
};

#endif // TASK_HPP

Task.cpp
#include "Task.hpp"

#include <SFML/System.hpp>
#include <sstream>
#include <iostream>

Task::Task() : mFPS(sf::String("FPS: 30")),
                           mUPS(sf::String("UPS: 30")),
                           mRun(false),
                           mLocker(),
                           mFont()
{
        mFont.LoadFromFile("FreeMono.ttf");

        mFPS.SetFont(mFont);
        mFPS.SetPosition(sf::Vector2f(10.f, 10.f));
        mFPS.SetColor(sf::Color::White);

        mUPS.SetFont(mFont);
        mUPS.SetPosition(sf::Vector2f(10.f, 50.f));
        mUPS.SetColor(sf::Color::White);
}

Task::~Task() { }

void Task::Draw()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
        window.SetFramerateLimit(30);
        sf::Clock clock;

        float currentFPS = 30;

        while(mRun)
        {
                // Process events
                sf::Event event;
                while (window.PollEvent(event))
                {
                        // Close window : exit
                        if (event.Type == sf::Event::Closed)
                        {
                                mRun = false;
                                window.Close();
                        }
                }

                std::stringstream ss;
                currentFPS = 1.f/clock.GetElapsedTime().AsSeconds();
                ss << "FPS: " << currentFPS;
                std::cout << ss.str() << std::endl;
                mFPS.SetString(sf::String(ss.str()));

                window.Clear();
                window.Draw(mFPS);
                window.Draw(mUPS);
                window.Display();

                // Reset
                clock.Restart();
        }
}

void Task::Update()
{
        sf::Clock clock;

        float currentUPS = 30;

        while(mRun)
        {
                currentUPS = 1.f/clock.GetElapsedTime().AsSeconds();
                std::ostringstream oss;
                oss << "UPS: " << (unsigned int)(currentUPS);
                {
                        sf::Lock::Lock(mLocker);
                        mUPS.SetString(sf::String(oss.str()));
                }

                // Reset
                clock.Restart();
        }
}

void Task::Run()
{
        mRun = true;

        sf::Thread thread1(&Task::Draw, this);
        thread1.Launch();

        sf::Thread thread2(&Task::Update, this);
        thread2.Launch();

        thread2.Wait();
        thread1.Wait();
}

Thanks for any help!

eXpl0it3r

Pages: 1 ... 4 5 [6] 7