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.


Messages - eXpl0it3r

Pages: 1 ... 634 635 [636] 637 638 ... 719
9526
Graphics / Re: Fading without artifacts
« on: October 01, 2012, 11:38:48 am »
IIRC it's not very good to not clear the RenderTexture every frame iteration, so you might want to keep track of all the objects you have and fade one after the other slowly.

For example like this:
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 300), "Test");
    window.setFramerateLimit(60);

    sf::Vector2f old_pos(0, 0);
    static const int STEP = 5;

    std::vector<sf::CircleShape> points;

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }

        sf::Vector2f pos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
        if(pos != old_pos)
        {
            sf::CircleShape cs;
            cs.setRadius(10);
            cs.setPosition(pos);
            cs.setFillColor(sf::Color::Red);
            points.push_back(cs);

            old_pos = pos;
        }

        window.clear();

        for(auto it = points.begin(); it != points.end(); ++it)
        {
            window.draw(*it);
            if(it->getFillColor().a-STEP < 0)
                it = points.erase(it);
            else
                it->setFillColor(sf::Color(255, 0, 0, it->getFillColor().a-STEP));
        }

        window.display();
    }
}
 

Keep in mind that calling erase on a std::vector isn't very performant and could be avoided with a better structure. With another structure you could also make use of that the fading process is linear and thus the oldest element can get removed first. Also to minimize the memory usage/object creation you could also just store the positions and draw a single shape/sprite/etc. while changing it's position and it's transparency.

I guess there could be other ways but that was just the most straight forward one that popped into my head.

9527
Network / Re: Complete newbie q's
« on: September 30, 2012, 07:33:58 pm »
The example chat uses sf::Thread. Are threads speed independent of the game fps. So, for example, the "threads cycle" will run faster on a faster computer not matter if the fps is set to a specific value?
Or are threads co-dependent on the game's fps?
Depends on how you limit the FPS.
If you use setFramerateLimit then only the thread that holds the window will get limited and if you set VSync then only the thread that draws will be limited.
Keep in mind threads can be completely independent applications (see here for more information).

9528
Window / Re: window becomes unresponsive on launch
« on: September 30, 2012, 07:30:00 pm »
#ifdef __cplusplus
extern "C" {
#endif
Wait what? Don't do that... :o
Or is that some strange Mac/Object-C related thing?

Well SFML 1.6 is anyways over 3 years old, has many known bugs and lacks quite a bit a feature so IMHO there's no reason to use SFML 1.6 anymore. ;)

9529
Graphics / Re: back buffering problem?
« on: September 30, 2012, 07:26:18 pm »
I am using SFML 2.0 and window.clear does not exist in 2.0. I have added window.setActive(); though which doesn't seem to help but seems appropiate.
Oh well my bad then, didn't notice that you were using the plain sf::Window class and not the sf::RenderWindow. ;)
Yes in this case you'll have to call the OpenGL equivalent glClear.

9530
Graphics / Re: PNG refuses to draw
« on: September 30, 2012, 07:23:36 pm »
It wasn't until I took a few lines out that the built-in "Could not activate windows context" errors started flooding the console.
That's exactly why we always say: 'Can you please show a complete and minimal code that reproduces the problem?' So people got and minimize their code and very often in doing so they find their errors on their own... ;)
That's what 'bug hunting' is all about, throwing out stuff that hasn't anything to do with it and narrowing the problem in until the code is so small that it's obvious. ;)

9531
General discussions / Re: Pixel Engine
« on: September 30, 2012, 07:15:04 pm »
If you want to know how they did it, go to their forum/IRC channel and asked there... ;)
Otherwise you could try to contact Naufr4g0 about the source for Tiny Bomber.
And if none of these options worked, simply asked Google about 'destructible terrain 2D' or similar.

9532
General / Re: static link errors with SFML 1.6 and VS2005
« on: September 29, 2012, 10:41:48 pm »
I picked 1.6 because it is the last version that supports vs2005 and xcode 3.
It's supported but there are no precompiled binaries. Is there a specific reason why you can't swith to VS10 (the express version is free and should be more than enough)?

Do you suggest that I must download version 2.0 and compile it myself to use it under vs2005 and under xcode 3?
Yes I do!

I thought it is not compatible at least with xcode 3.
What are my SFML options for xcode 3?
When you recompile SFML on your own, I guess it should work, then again I've never worked with a Mac.

So your suggestions for cmake/nmake are bit exotic to me.
I've never suggested CMake, but well it would be the best solution. If you don't know it and plan on staying with C++ a bit longer you should definitely look into it!
Of course you can also just manually use the project files for VS + xcode for setting up the compiler and linker.

I wouldn't agree with your objection for the #pragma comment to link libraries.
You write that after you've stated:
C++ is not my primary language. I come from the delphi world where all these linking is solved by the tool and you are never bothered with such issues.
You can ask about any (good) C++ developer if it's good to use #pragma comment when writing crossplatform code and all of them will say NO!... ;)
Sure you can do what ever you want, but I'm not going to look through that 'config' file. :D

I find it very logical that each unit (if used) should bring in its own dependencies, and free the developer from going to other places in the tool to add paths and libraries.
Well if you speak in general terms, then you'd have to write 20+ different setup files to support all the major IDEs/compilers...
For that reason CMake and other tools where introduced which generate make or projects files for a big majority of IDEs/compilers from a small CMakeLists.txt file.

9533
Well we're not here to program for you, also as you mentioned this is mainly a mathematical problem and the transformation from math to code should be quite obvious once you understood what the math does.
So sit down, take your time, think about it, read stuff on math if you don't get it and then implement it and if you got stuck there come back here. ;)

9534
I have no idea how SFML and Qt are connected but to resize a sf::RenderWindow you simply create a new one, i.e. call the create(...) function on the render window object.

9535
General / Re: static link errors with SFML 1.6 and VS2005
« on: September 29, 2012, 04:59:28 pm »
Don't use SFML 1.6, it's over 3 years old.
DON'T use #pragma comment to link stuff, specially since you're trying to get things cross platform. Linking settings have nothing to do with application code but are part of the project and thus should be put into the project file/nmake file/make file!!! >:(

Follow the tutorials and you should be fine.

9536
Graphics / Re: Possible bug in sf::Text
« on: September 29, 2012, 10:10:39 am »
well I just checked the latest source and it hasn't been fixed yet.
How did you check, because it has been committed two days ago.

Delete all the old files, download SFML from source, use CMake to generate makefiles (see tutorial), build SMFL and then you can use if with your application.

9537
General discussions / Re: How do I implement a main menu.
« on: September 29, 2012, 10:06:29 am »
One often uses some kind of state manager to handle different states in a game (e.g. game mode + menu). A nice way is to do this with classes, but a simple switch/if statement can do the trick too. You can find some example on the wiki or you can take a look at my simple state manager.

As for buttons, first just think about what a button essentially is. It's just an image that changes its look when being pressed or hovered over it. For an implementation you can either construct such a button with shapes or use a texture. Then you can get key stroke or mouse input with the sf::Keyboard and sf::Mouse. To check whether the mouse is over a button you can make use of the contains() function of a sf::Rect.

Learning things by doing it can work to some parts, but you won't learn new techniques, thus it's better to look around in the wiki section or look at existing code etc...

9538
Graphics / Re: back buffering problem?
« on: September 29, 2012, 09:38:46 am »
You should always clear the window, draw your stuff and then display it.
Keep in mind that drawing it once and hoping it will always stay there is a bad idea, because as soon as you drag some window in front of yours the information will get overwritten.

#include <SFML/Graphics.hpp>
#include <GL/glew.h>

using namespace sf;

struct point
{
        float x, y; // z is always 0 ... for now. MWUAHAHAA
};

point points[3] = {{0.f, 1.f},     // top
                                   {-1.f, -1.f},   // left
                                   { 1.f, -1.f}};  // right

point temp = {points[0].x, points[0].y};

void renderFirstTriangle()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glBegin(GL_TRIANGLES);

                glColor3f(1.f, 1.f, 1.f);
                glVertex3f(points[0].x, points[0].y, 0.f);

                glColor3f(1.f, 1.f, 1.f);
                glVertex3f(points[1].x, points[1].y, 0.f);

                glColor3f(1.f, 1.f, 1.f);
                glVertex3f(points[2].x, points[2].y, 0.f);

                glEnd();
}

int main()
{
    Window window(VideoMode(800, 600), "Fractal", Style::Default, ContextSettings(32));
    window.setVerticalSyncEnabled(true);

        while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
                        if (event.type == Event::Resized)
                glViewport(0, 0, event.size.width, event.size.height);

                        else if (event.type == Event::Closed)
                                window.close();
        }

                window.clear();
                renderFirstTriangle();

                for (int i = 0; i < 3; i++)
                {
                        // calculate new vertex positions

                        temp.x = points[0].x;
                        temp.y = points[0].y;

                        glBegin(GL_TRIANGLES);
                       
                        if( i % 2 )
                                glColor3f(0.1f, 0.1f, 0.1f);

                        glVertex3f((points[0].x + points[1].x) / 2, (points[0].y + points[1].y) / 2, 0.0f);
                        glVertex3f((points[1].x + points[2].x) / 2, (points[1].y + points[2].y) / 2, 0.0f);
                        glVertex3f((points[2].x + temp.x) / 2, (points[2].y + temp.y) / 2, 0.0f);
                       
                        glEnd();
                }
                window.display();
        }
}

9539
From the two header files you include I judge that you're using C++11 and thus probably using GCC 4.7. To use SFML 2 with GCC 4.7 you have to recompile SFML completly.

As for the code there's the function window.setFramerateLimit() so you don't have to do this on your own with std::this_thread::sleep_for(interval).
It's also not advised to use Vsync and a manual limiter. Use on or the other but not both!
When using std::string you should also include it's header.

9540
General discussions / Re: SFML 2.0 RC
« on: September 29, 2012, 12:37:20 am »
Are you using the express edition by any chance?
Well this could likely be, since I'm using Visual Studio 12 Premium (thanks university!). ;)

Pages: 1 ... 634 635 [636] 637 638 ... 719
anything