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

Pages: [1] 2
1
Graphics / Motion Blur GLSL
« on: March 13, 2016, 05:57:37 pm »
Hello,

I'm trying to load a motion blur shader in GLSL using sf::Shader, however I'm having some trouble applying it to a sprite, as it seems to be completely hide it (i.e. the sprite isn't even drawn, maybe it's loosing its alpha value?) instead of blurring on movement. I've implemented a minimal snippet that reproduces this problem, but I'm inclined to say the problem relies with the GLSL shaders. I've also attached the shaders and resources to this post.

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

const double PI = std::atan(1.0) * 4;

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader",
                sf::Style::Titlebar | sf::Style::Close);

        window.setFramerateLimit(60.f);

        sf::Texture m_texture;
        if (!m_texture.loadFromFile("eff08b.png"))
                return EXIT_FAILURE;

        sf::Sprite m_sprite;
        m_sprite.setTexture(m_texture);
        m_sprite.setOrigin(m_sprite.getGlobalBounds().width / 2.f, m_sprite.getGlobalBounds().height / 2.f);

        sf::Shader m_shader;
        if (!m_shader.loadFromFile("motionblur.vert", "motionblur.frag"))
                return EXIT_FAILURE;

        m_shader.setParameter("scene", sf::Shader::CurrentTexture);

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

                float amplitude = 100.f;
                m_sprite.setPosition(amplitude * std::sin(PI * 0.5 * time.getElapsedTime().asSeconds()) + 400.f, 300.f);
                m_sprite.rotate(5.f);

                window.clear(sf::Color(255, 255, 255));
                window.draw(m_sprite, &m_shader);
                window.display();
        }

        return EXIT_SUCCESS;
}

Sadly I'm not too experienced in GLSL, so ended up using this implementation (slide 29): http://www.stevenlu.net/files/motion_blur_2d/Fragment_shader_dynamic_blur.pdf .

Am I missing something really simple?

Best regards

2
System / Problem with sf::sleep (freeze)
« on: February 19, 2014, 11:39:05 am »
Hello,

For some reason using an sf::sleep with an std::cout and no std::endl makes my program freeze forever:

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

int main(int argc, char ** argv)
{
    while(true)
    {
        std::cout << "here";
        sf::sleep(sf::seconds(0.5f));
    }

        return 0;
}
 

However if I remove sf::sleep or if I add std::cout << "here" << std::endl; it works just fine. In addition, this was compiled in Ubuntu 12.04 (64-bit) with g++ 4.6.3, but for some reason the problem doesn't seem to happen in Windows (compiled with mingw/g++ 4.8 ).

What could be the problem here?

Thanks in advance,
Best regards

EDIT: Adding a std::cin.ignore(std::numeric_limits<int>::max(),'\n'); also seems to fix the problem for a while. This leads me to believe it could be a buffer problem? But why does sf::sleep affect this?

EDIT: Adding an std::flush also seems to work.

3
General / Visual Studio 2013 and MinGW, linker with unresolved externals
« on: November 12, 2013, 08:32:03 am »
Hey guys

I'm trying to compile an example project with the static SFML 2.1 libs using both compilers mentioned in the title.
For some reason both compilers give me the following unresolved externals for the example source code I'll post next:

Code: [Select]
error LNK2001: unresolved external symbol __imp__glBlendFunc@8
error LNK2001: unresolved external symbol __imp__glClear@4
error LNK2001: unresolved external symbol __imp__glClearColor@16
error LNK2001: unresolved external symbol __imp__glColorPointer@16
error LNK2001: unresolved external symbol __imp__glDisable@4
error LNK2001: unresolved external symbol __imp__glDrawArrays@12
error LNK2001: unresolved external symbol __imp__glEnable@4
error LNK2001: unresolved external symbol __imp__glEnable@4
error LNK2001: unresolved external symbol __imp__glEnableClientState@4
error LNK2001: unresolved external symbol __imp__glLoadMatrixf@4
error LNK2001: unresolved external symbol __imp__glLoadMatrixf@4
error LNK2001: unresolved external symbol __imp__glMatrixMode@4
error LNK2001: unresolved external symbol __imp__glMatrixMode@4

The source code is from the tutorial example:
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

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

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

I'm linking against: sfml-audio-s.lib, sfml-graphics-s.lib, sfml-window-s.lib, sfml-system-s.lib, on Release settings. SFML_STATIC is defined in the Preprocessor. I've recompiled SFML from source for each compiler, the linker errors are the same (or very similar).

I don't know what I could be missing here. They seem to be related to openGL, but I'm not using it directly anywhere, well maybe except for SFML itself. Any heads up?

Thank you for your time.

EDIT:
I think I should mention that I was previously using SFML 2 with windows 7, everything was working fine. Now I've reformatted to windows 8.1 and this started to happened. Graphics drivers are up to date as well.

4
Audio / Odd sound quality (fixed)
« on: August 23, 2012, 09:33:21 pm »
Hello everyone,

I'm trying to play a simple .wav sound using the minimal code shown bellow. It plays fine, however the quality of the sound being played by the application, sounds significantly worse in quality when compared to the original.

It's hard to describe but it sounds like it's missing some frequencies or like really bad quality like a 12kbps mp3 sound. I know this explanation is really daft and I which I could record it or show it somehow.

Also, this doesn't seem to happen with all sounds. Only on sounds with 1 channel or mono but I'm not very sure. If someone could give me a hint I'd be thankful.

Here's my minimal code:
#include <SFML/Audio.hpp>
int main()
{
    sf::SoundBuffer sb;
    sb.loadFromFile("engine.wav");

    sf::Sound sound;
    sound.setBuffer(sb);
    sound.play();
    while(sound.getStatus() == sf::Sound::Playing)
    {}
    return 0;
}

Here's engine.wav from the example: https://dl.dropbox.com/u/8365167/engine.wav
And here's a 2 channel .wav that seems to play just fine: https://dl.dropbox.com/u/8365167/se_powerup.wav

Best regards, and thanks again.

5
Graphics / sf::Text ignoring spaces at the end
« on: February 07, 2012, 11:00:15 am »
Hello,

sf::Text seems to be ignoring blank spaces I put at the end of a string. When I try to get the Global Bounds's width it always returns the value of the string without the spaces
The problem is shown by the code:

Code: [Select]
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
sf::Text text1("Hello this is a string");
sf::Text text2("Hello this is a string    ");

std::cout << "Bounds for text1: " << text1.GetGlobalBounds().Width << std::endl;
std::cout << "Bounds for text2: " << text2.GetGlobalBounds().Width << std::endl;

getchar();
return 0;
}


Is this behaviour intentional?
Is there a workaround?

Using latest commit of SFML,
Windows 7,
ATI Radeon HD4870.

Best Regards.

6
General / Image Manager Destruction (Solved)
« on: January 01, 2012, 12:19:41 am »
Hello,

I'm using an image manager based on the following file:
http://www.sfml-dev.org/wiki/fr/sources/imagemanager

I'm using the manager as a global variable as it makes things easier, although I'm not sure if I should go with this or a singleton.

But that aside, I'm having some trouble trying to understand why the program simply crashes when exiting. For some reason the call stack points to the destructor on the line:
Code: [Select]
delete it->second;

The application runs fine, but when exiting, it crashes. Although It only happens if the manager is a global. If it's inside the main then there's no problem.

What is causing this? What can I do to avoid this?
Also, I'm compiling with Visual Studio 2008.
Thanks in advance and happy new year  :)

7
General / Best container
« on: August 12, 2011, 07:55:56 am »
Hi,
I was wondering which container would be the best to use to manage a large number of objects (1000 and up). When I say "best" I mean the fastest to access, delete, add new members, etc.

I usually use std::vector but I've read before that it's quite inefficient and I'm starting to believe that this is true since I notice many flickering objects when many are being added and deleted at the same time.

Which container would be the best to use in this situation? Are there any alternatives besides std containers? What if I use an object array (for example: object
  • )? No, maybe I'm going too deep.

8
General / Simple operator overloading question
« on: July 29, 2011, 06:18:00 am »
Hello, I was reading the following page from the wiki:
http://www.sfml-dev.org/wiki/en/sources/richtext

On the following function:
Code: [Select]
RichText & RichText::operator << (const sf::Color &color)
{
myCurrentColor = color;
return *this;
}

What is the "return *this" doing here exactly? Isn't the first line "myCurrentColor = color;" enough to set a new color value?

I know this is probably a simple matter but I came from a C programming background and I haven't mastered Operator Overloading too well yet.

Thanks in advance for the help,
Regards,
Alex.

9
Graphics / SFML 2.0: GetFrameTime
« on: May 25, 2011, 08:59:44 pm »
Hi,
I've updated SFML 2.0 to the latest snapshot today and for some reason whenever I use GetFrameTime it's returning me 15.0 while I'm limiting the frames to 60.
I've confirmed that the frames are limited to 60 with Fraps but the function seems to return a strange value. Were there any changes on this function lately? I can't find anything on the documentation.

Also EnableVerticalSync doesn't seem to work anymore. The frames fire up to 5000 when I'm using it and GetFrameTime returns 0.

Everything worked fine before I've updated so I don't know what could be wrong. Compiled with VS10 and CodeBlock's MinGW and both act like this.

Thanks in advance for any input.

10
General / Quick reference question.
« on: April 10, 2011, 07:10:52 pm »
Hello, I'm having a bit of trouble thinking of a way to pass an sf::RenderWindow object to another class.

In the main I have object "Window"
Code: [Select]
int main
{
sf::RenderWindow Window(sf::VideoMode(1024,768,32),"Default");
[...]
}


And I want to pass this object to a class "cTest".
I tried it like this:
Code: [Select]
class cTest
{
sf::RenderWindow& m_Window;
cTest(sf::RenderWindow& Window):m_Window(Window);
};



Final Code:
Code: [Select]
class cTest
{
sf::RenderWindow& m_Window;
cTest(sf::RenderWindow& Window):m_Window(Window);
};

int main
{
sf::RenderWindow Window(sf::VideoMode(1024,768,32),"Default");
[...]
        cTest otest(Window);
        [...]
}


I does seem too work but I can't stop shaking the feel that this isn't the correct way to do this. Could someone enlighten me please?

Thanks in advance  :)

11
General / GetInput() trouble
« on: March 23, 2011, 05:02:30 am »
Hello,
I have the following code that allows a sprite to move (in this case the main player's sprite) using the default arrow keys:

Code: [Select]
void NewPlayer::ProcessInputs(sf::RenderWindow &Target)
{
    //The code follows:
    //If an arrow key is pressed
    //If the sprite if bellow or above the axis value required
    //Move the sprite

    //UP
    if(Target.GetInput().IsKeyDown(sf::Key::Up))
        if(splayer.GetPosition().y > 40.0)
            splayer.Move(0,-m_movespeed);

    //DOWN
    if(Target.GetInput().IsKeyDown(sf::Key::Down))
        if(splayer.GetPosition().y < 730.0)
            splayer.Move(0,m_movespeed);

    //LEFT
    if(Target.GetInput().IsKeyDown(sf::Key::Left))
        if(splayer.GetPosition().x > 240)
            splayer.Move(-m_movespeed,0);

    //RIGHT
    if(Target.GetInput().IsKeyDown(sf::Key::Right))
        if(splayer.GetPosition().x < 780.0)
            splayer.Move(m_movespeed,0);

}


However it's glitching me a bit.
If the sprite reaches the top of the screen and if i keep pressing UP, the sprite doesn't move, good!
However if I keep pressing UP and then press DOWN at the same time, the sprite nudges down a bit and doesn't move until I release UP.
The only problem here is that little nudge. Even though it's just a small movement, it feels really strange during gameplay.
EDIT: (The same thing happens with Left and Right Keys)

Here's a picture to understand better what happens:

Left: Just Pressing UP
Right: Pressing UP and DOWN

What could I change in my code to fix this?
Thanks in advance

12
Graphics / Changing global alpha (Transparency)
« on: February 09, 2011, 05:35:16 pm »
Hello,
Is it possible to change the global alpha/transparency of all the contents on the window at once or do I have to change it individually for each object?

I tried using sf::RenderWindow::Clear(sf::Color(255,255,255,0)) but I believe that only changes the background settings with which the screen is cleared.

Thanks in advance  :)

13
General / Detecting Memory Leaks
« on: December 23, 2010, 08:00:59 pm »
Hi,
I wrote an sf::Image manager called "class imStorage" based on an resource manager on the wiki and used Visual Studio 2010's debug mode to detect memory leaks.
For some reason, it's detecting a whole bunch of leaks, however I'm having trouble identifying what could be wrong.

Every image is stored on an std::map:
Code: [Select]
std::map<std::string,sf::Image*> bStore

Here's is the code for getting an image:
Code: [Select]

sf::Image *imStorage::GetImage(std::string Link)
{
    //if the image is already in the map, then return the image from it
    if(SearchManager(Link))
    {
        return bStore[Link];
    }
    //else allocate it from a Link to the path
    else
    {
        sf::Image *bHolder = new sf::Image;

        if(bHolder->LoadFromFile(Link))
        {
            bStore.insert(std::pair<std::string,sf::Image*>(Link,bHolder));
            std::cout << "Gestor de Imagens $ Inserido: " << Link << std::endl;
            return bStore[Link];
        }
        else
        {
        delete bHolder;
        }
return NULL;
    }
return NULL;
}

bool imStorage::SearchManager(std::string Link)
{
    std::map<std::string,sf::Image*>::iterator it;
    it = bStore.find(Link);
    if(it != bStore.end())
    {
        return true;
    }
    else return false;
}





And finally here's the destructor:
Code: [Select]
imStorage::~imStorage()
{
while(bStore.begin()!=bStore.end())
{
delete bStore.begin()->second;
bStore.erase(bStore.begin());
}

}


I get the following messages after executing:
Quote
Detected memory leaks!
Dumping objects ->
{136} normal block at 0x00334C20, 8 bytes long.
 Data: < S      > 14 53 1F 00 00 00 00 00
{135} normal block at 0x00334BD0, 20 bytes long.
 Data: < K3  K3  K3     > D0 4B 33 00 D0 4B 33 00 D0 4B 33 00 CD CD CD CD
{134} normal block at 0x00334B88, 8 bytes long.
 Data: < I3     > D4 49 33 00 00 00 00 00
{133} normal block at 0x003349C8, 384 bytes long.
 Data: <$            K3 > 24 CE 1E 00 01 00 00 00 01 00 00 00 88 4B 33 00
{132} normal block at 0x00334988, 4 bytes long.
 Data: < I3 > C8 49 33 00
Object dump complete.


Problem is, I have no idea what these mean and I can't identify what's causing the leaks.
What could be wrong? Could it be a false positive? Should I use any other memory leak detection tool?

If you have any idea or suggestion please be sure to give me a heads up.
Thanks in advance  :)

14
General / Width of an sf::String
« on: December 22, 2010, 07:10:46 pm »
Hi, is there any way to get the width of an sf::String like in a sf::Sprite (sf::Sprite::GetSize().x).

I'm trying to create a window with "x" width and "x" would have the width of the sf::String.

Is this possible or I have to configure this manually?
Font size will be always 20.

Thanks in advance
 :)

15
General / Best way to load the same image multiple times
« on: November 16, 2010, 11:15:01 am »
Hi,
I'm trying to write a program with a class called wBullet that calls a Sprite with a png image.
This class bullet will create at least 100 objects, and so I was wondering what's the best way to load the same image so many times?

Here's my prototype class:

Code: [Select]
//bullet.hpp

class wBullet
{
    int speed;
    double x,y;
    Sprite bullet;
    wBullet();
};



Code: [Select]
//bullet.cpp
wBullet::wBullet()
{
    bullet.LoadFromFile("b.png");
}



Should I use Sprite::LoadFromFile every time? Will it cause any impact? Or should I try Sprite::LoadFromMemory?

Also, what would be the best way to store all these objects?
An array:
wBullet o1["size of array"]
A vector :
vector<wBullet> o1;
Or anything else?

I understand these are probably newbie questions, but I'm fairly new to C++.

Thanks in advance, keep up the great work!

Pages: [1] 2
anything