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

Pages: [1] 2 3 4
1
Audio / No sound is played. (When loading with samples)
« on: January 27, 2016, 09:01:12 pm »
Hi!
I want to play an ultra sound but no sound is played.

Actually I'm on ubuntu 14.04 64 bits version.

Here is the code.

#include <SFML/Audio.hpp>
int main(int argc, char* argv[]) {
    std::vector<sf::Int16> samples = {10000};
    sf::SoundBuffer buffer;
    buffer.loadFromSamples(samples.data(),samples.size(),1,44100);
    sf::Sound sound;
    sound.setBuffer(buffer);
    sound.setLoop(true);
    sound.play();
    while (true) {}

    return 0;
}
 

I've turn down the frequency to listen if it works.

2
Graphics / Problem with character size.
« on: January 21, 2016, 11:27:49 am »
Hi!

I've a problem with the character size :

I want to make a text area, so, each time I enter text, I advance the cursor like this :

cursorPos.x += text.getCharacterSize();
 

The problem is that the cursor advance faster than the glyph.

So I don't think that the getCharacterSize function member is returning the right character size.

I've also difficulties to adapt text size to the size of my labels...

Is that method returning the size of one character ?

3
General / Why is sf::String removing unknow ascii characters ?
« on: December 31, 2015, 09:43:52 am »
Hi, I've coded a custom filedialog, the problem is when my std::string contains the character 'é' by example, the character is removed by sf::String and it fails to open my file.
std::string Label::getText() {
       return text.getString().toAnsiString();
}
 
std::string currentDir = lTop.getText();
std::cout<<fileName<<std::endl;
currentDir += "/"+fileName;
std::cout<<currentDir<<std::endl;
std::string currentDir = lTop.getText();
std::cout<<fileName<<std::endl;
currentDir += "/"+fileName;
std::cout<<currentDir<<std::endl;
lTop.setText(currentDir);
if (DIR* current = opendir(currentDir.c_str())) {
 
By exemple sf::String replace développement by dveloppement and I get a no such file or directory error. (Wtf  :o)
So I've just changed the type of sf::String to std::string into the sf::Text class and now it works.

There isn't any unicode version of the opendir function, so I really suggest you to don't remove unknow characters for ansi strings.

4
General / When a support for a core context ?
« on: October 26, 2015, 10:41:22 am »
Hi!

I've tried to create an opengl 4.2 core context on windows with SFML but it doesn't seem that SFML support it yet.

Only older versions of opengl are working.

So, when I execute a code with moddern opengl, it crash.

But with glfw I don't have any problem.

Do you plan to add an SFML support for modern opengl one day ?

5
Feature requests / Multiple render target.
« on: May 04, 2015, 09:22:37 pm »
Hi, I'm more and more interested by modern opengl for optimisation purposes, so I tend to get away more and more from SFML but I still like this library because it's really the library which one I've learned everything!

Now I'm finally able to display objects with modern opengl and then with instanced rendering and image load-store soon for my custom depth test and my order independant transparency algorithm, I'm just wondering, what'll be about SFML ?

Will you change the class rendertarget for multiple target rendering and add some modern opengl functionnalities like I do or will you just let SFML like it's now because it's sufficient for 2D games ?

6
Audio / Sound which is repeating.
« on: April 02, 2015, 10:01:01 pm »
Hi!
Sorry if my question is stupid and if I've missed something in the doc but :

I've created a custom audio stream like explained in the tutorial :

void Stream::load(const sf::SoundBuffer& buffer)
        {
            m_file = nullptr;
            // extract the audio samples from the sound buffer to our own container
            m_samples.assign(buffer.getSamples(), buffer.getSamples() + buffer.getSampleCount());

            // reset the current playing position
            m_currentSample = 0;

            // initialize the base class
            SoundStream::initialize(buffer.getChannelCount(), buffer.getSampleRate());
        }
        ////////////////////////////////////////////////////////////
        bool Stream::openFromFile(const std::string& filename)
        {
            // First stop the music if it was already running
            m_file = new priv::SoundFile();
            stop();

            // Open the underlying sound file
            if (!m_file->openRead(filename))
                return false;

            // Perform common initializations
            initialize();

            return true;
        }


        ////////////////////////////////////////////////////////////
        bool Stream::openFromMemory(const void* data, std::size_t sizeInBytes)
        {
            m_file = new priv::SoundFile();
            // First stop the music if it was already running
            stop();

            // Open the underlying sound file
            if (!m_file->openRead(data, sizeInBytes))
                return false;

            // Perform common initializations
            initialize();

            return true;
        }


        ////////////////////////////////////////////////////////////
        bool Stream::openFromStream(InputStream& stream)
        {
            m_file = new priv::SoundFile();
            // First stop the music if it was already running
            stop();

            // Open the underlying sound file
            if (!m_file->openRead(stream))
                return false;

            // Perform common initializations
            initialize();

            return true;
        }
        bool Stream::onGetData(Chunk& data)
        {
            Lock lock(m_mutex);
            if (m_file == nullptr) {
                // number of samples to stream every time the function is called;
                // in a more robust implementation, it would rather be a fixed
                // amount of time rather than an arbitrary number of samples
                const int samplesToStream = 50000;

                // set the pointer to the next audio samples to be played
                data.samples = &m_samples[m_currentSample];

                // have we reached the end of the sound?
                if (m_currentSample + samplesToStream <= m_samples.size())
                {
                    // end not reached: stream the samples and continue
                    data.sampleCount = samplesToStream;
                    m_currentSample += samplesToStream;
                    return true;
                }
                else
                {
                    // end of stream reached: stream the remaining samples and stop playback
                    data.sampleCount = m_samples.size() - m_currentSample;
                    m_currentSample = m_samples.size();
                    return false;
                }
            } else {
                // Fill the chunk parameters
                data.samples     = &m_samples[0];
                data.sampleCount = m_file->read(&m_samples[0], m_samples.size());

                // Check if we have reached the end of the audio file
                return data.sampleCount == m_samples.size();
            }
        }

        void Stream::onSeek(sf::Time timeOffset)
        {
            // compute the corresponding sample index according to the sample rate and channel count
            m_currentSample = static_cast<std::size_t>(timeOffset.asSeconds() * getSampleRate() * getChannelCount());
        }
        void Stream::initialize()
        {
            // Compute the music duration
            m_duration = seconds(static_cast<float>(m_file->getSampleCount()) / m_file->getSampleRate() / m_file->getChannelCount());

            // Resize the internal buffer so that it can contain 1 second of audio samples
            m_samples.resize(m_file->getSampleRate() * m_file->getChannelCount());

            // Initialize the stream
            SoundStream::initialize(m_file->getChannelCount(), m_file->getSampleRate());
        }
 

I've also created a class to play the song but I want to use only one class for playing sounds and musics :

Player::Player(SoundBuffer& buffer) {
             Stream* stream = new Stream();
             stream->load(buffer);
             this->stream = stream;
        }
        void Player::setAudioStream(SoundStream* stream) {
             this->stream = stream;
        }
        sf::SoundStream* Player::getAudioStream() {
            return stream;
        }
        void Player::play(bool loop) {
             stream->setLoop(loop);
             stream->play();
        }
        void Player::stop() {
             stream->stop();
        }
        void Player::pause() {
             stream->pause();
        }
        Player::~Player() {
            delete stream;
        }
 

The problem is that the sound is playing repeatively :

int main (int argv,char* argc[]) {
    sf::SoundBuffer buffer;
    buffer.loadFromFile("sounds/ballhurtbar.wav");
    odfaeg::audio::Stream stream;
    stream.load(buffer);
    odfaeg::audio::Player player;
    player.setAudioStream(&stream);
    player.play(false);
    const auto delay = sf::milliseconds(1);
    do {
        sf::sleep(delay);
    } while(stream.getStatus() == odfaeg::audio::Stream::Playing);
    return 0;
 

Isn't the sound supposed to be stopped when the onGetData method return false ?

Or I've I missunderstand something ?

7
Audio / Sound who doens't play.
« on: April 02, 2015, 07:46:49 pm »
Hi!

I'm trying to play a sound but it doesn't play :

int main() {
    sf::SoundBuffer buffer;
    buffer.loadFromFile ("sounds/ballhurtbar.wav");
    sf::Sound sound;
    sound.setBuffer(buffer);
    sound.play();
    return 0;
}
 

OS : ubuntu LTS 64 bits.
SFML version : 2.2.

8
Hi!

I have a set of faces that I want to draw, I don't want to use default opengl blending and depth test because it's a very complex scene.

I've tried to perform instanced rendering but the problem is that SFML updates the render texture each time that something is drawn and not each time that a pixel is updated with the sahder, so, I can't get the right colour for faces which overlap in my shader using instanced rendering.

So I  update the render texture each time I render a face, so I do more draw calls but it's slower.

My question is simple so, isn't there a way to update the render texture each time a pixel is written on the render teture with the shader ?

I don't know opengl very well so it's why I'm asking this question.

9
Window / Creating a window in a window.
« on: February 15, 2015, 09:34:03 am »
Hi!

I need to create a window in a window for my game. (Confirmation and message dialogs.)

So I've just created this class :

OptionPane::OptionPane(math::Vec3f position, math::Vec3f size, const Font* font, sf::String t, TYPE type) :
                LightComponent (position, size, size * 0.5f, false),
                rw (sf::VideoMode(size.x, size.y), "Option Pane", sf::Style::Default, sf::ContextSettings(0, 0, 4, 3, 0)),
                type(type) {
                rw.getView().move(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
                if (type == CONFIRMATION_DIALOG) {
                    yes = new Button(math::Vec2f(size.x / 100 * 70, size.y - 100), math::Vec2f(100, 50), font, "Yes", rw);
                    no = new Button(math::Vec2f(size.x / 100 * 10, size.y - 100), math::Vec2f(100, 50), font, "No", rw);
                    core::FastDelegate<bool> trigger1(&Button::isMouseInButton, yes);
                    core::FastDelegate<bool> trigger2(&Button::isMouseInButton, no);
                    core::FastDelegate<void> slot1(&OptionPane::onYesOption, this);
                    core::FastDelegate<void> slot2(&OptionPane::onNoOption, this);
                    core::Action a (core::Action::MOUSE_BUTTON_PRESSED_ONCE,sf::Mouse::Left);
                    core::Command cmd1 (a, trigger1, slot1);
                    core::Command cmd2 (a, trigger2, slot2);
                    getListener().connect("YESOPTION", cmd1);
                    getListener().connect("NOOPTION", cmd2);
                } else {
                    yes = nullptr;
                    no = nullptr;
                    core::Action a (core::Action::KEY_PRESSED_ONCE, sf::Keyboard::Return);
                    core::FastDelegate<void> slot(&OptionPane::onEnter, this);
                    core::Command cmd (a, slot);
                    getListener().connect("ONENTER", cmd);
                }
                rw.setPosition(sf::Vector2i(position.x, position.y));
                option = UNDEFINED;
                text.setFont(*font);
                text.setString(t);
                text.setColor(sf::Color::Black);
                text.setPosition(math::Vec3f(10, 10, position.z));
                text.setSize(size);
                backgroundColor = sf::Color::White;
            }
            void OptionPane::onVisibilityChanged(bool visible) {
                rw.setVisible(visible);
            }
            OptionPane::OPTION OptionPane::getOption() {
                OPTION choosenOption = option;
                option = UNDEFINED;
                return choosenOption;
            }
            void OptionPane::clear() {
                rw.clear(backgroundColor);
            }
            void OptionPane::draw(RenderTarget& target, RenderStates states) {
                if (rw.isOpen()) {
                    rw.draw(text, states);
                    if (type == CONFIRMATION_DIALOG)  {
                        rw.draw(*yes, states);
                        rw.draw(*no, states);
                    }
                    rw.display();
                }
            }
            void OptionPane::update() {
                sf::Event event;
                while(rw.pollEvent(event)) {
                    if (event.type == sf::Event::Closed) {
                        rw.setVisible(false);
                    }
                    getListener().pushEvent(event);
                }
            }
            void OptionPane::onEnter() {
                setVisible(false);
                setEventContextActivated(false);
                rw.setVisible(false);
            }
            void OptionPane::onYesOption() {
                rw.setVisible(false);
                setEventContextActivated(false);            
                option = YES_OPTION;
            }
            void OptionPane::onNoOption() {
                rw.setVisible(false);
                setEventContextActivated(false);            
                option = NO_OPTION;
            }
            void OptionPane::setText(std::string t) {
                text.setString(sf::String(t.c_str()));
            }
            OptionPane::~OptionPane() {
                rw.close();
                if (CONFIRMATION_DIALOG) {
                    delete yes;
                    delete no;
                }
            }
 

It works fine except for one point, here, I want to create two sub-windows :

m_pseudoUsed = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"Pseudo already used!",gui::OptionPane::TYPE::MESSAGE_DIALOG);
    m_pseudoUsed->setVisible(false);
    m_pseudoUsed->setEventContextActivated(false);
    m_confirmInvitation = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"",gui::OptionPane::TYPE::CONFIRMATION_DIALOG);
    m_confirmInvitation->setVisible(false);
    m_confirmInvitation->setEventContextActivated(false);
 

I set the visibility of my sub-windows to false, so the windows shouldn't be shown, but it's not what I see.

I see a transparent window on the main window, and the title is not always the title of my sub-windows..., this is really strange. :/

10
General / SFML 2.2 fails to compile.
« on: January 15, 2015, 10:54:14 am »
Hi!

I'm trying to compile SFML2.2 but I get this following error message when it tries to link the graphic module.

Code: [Select]
Linking CXX shared library ../../../lib/libsfml-graphics.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libglew.a(glew.o): réadressage de R_X86_64_32 en vertu de « .rodata » ne peut être utilisé lors de la création d'un objet partagé; recompilez avec -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libglew.a: error adding symbols: Mauvaise valeur
collect2: erreur: ld a retourné 1 code d'état d'exécution
make[2]: *** [lib/libsfml-graphics.so.2.2.0] Erreur 1
make[1]: *** [src/SFML/Graphics/CMakeFiles/sfml-graphics.dir/all] Erreur 2
make: *** [all] Erreur 2

What should I do ?

Thanks.

11
Window / Rendering in multithread cause crash. (On linux)
« on: January 14, 2015, 05:56:11 pm »
Hi, I've a very low FPS (15 FPS) in my project because the CPU is waiting after the GPU. :/

So, I want to render the scene in another thread because my scene is very complex.

The main purpose is to make my games more realistic. (Shadow, light, disfraction and refraction, etc...)

Most of all I've to apply the shaders in a specific ordre to handle the opacity.

So, I can't draw everything with a single draw call.

I've seen on your tutorials that it's possible to use a thread with SFML to draw the scene.

So, I've tried this with a minimal code. (No need to draw anything to repoduce the crash)
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
void renderingThread(sf::RenderWindow* window)
{
    // the rendering loop
    while (window->isOpen())
    {
        window->clear();
        window->display();
    }
}

int main (int argv, char* argc[]) {
    //XInitThreads();
     // create the window (remember: it's safer to create it in the main thread due to OS limitations)
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");

    // deactivate its OpenGL context
    window.setActive(false);

    // launch the rendering thread
    sf::Thread thread(&renderingThread, &window);
    thread.launch();
    // the event/logic/whatever loop
    while (window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
    }
    return 0;
}
 

Here is what it shows in the terminal :

Code: [Select]
[xcb] Unknow request in queue while dequeuing
[xcb]Most likely this is a multi-threaded client and XInitThreads has not been
called.
[xcb]Abording, sorry about that.
ODFAEG-DEMO: ../../src/xcb_io.c;179: dequeue_pending_request: Assertion '!xcb_xlib_unknown_req_in_deq' failed.
Aborded (core dumped)
Process returned 134 (0x86) execution time : 0.293 s
Press ENTER to continue.

I've tried to make what it says : calling XInitThreads at the frist line in the main but it doesn't solve the problem.

Is there another library than Xlib which support multi-threading with GUI on linux ?

I've heard about xcb but, I don't know it very well.

PS : I've also tried to use std::thread instead of sf::Thread but it still doesn't solve the problem.

Thanks for your help.

12
Audio / [SOLVED]Can't play several sounds at the same time. :/
« on: January 03, 2015, 05:16:24 pm »
Hi!

I've created a custom stream class which inherits from your SoundStream class.

I pass my custom stream to a player class (because sf::sound can only take a constant reference to a soundstream instance)

Code: [Select]
||=== Build: Debug in ODFAEG-DEMO (compiler: GNU GCC Compiler) ===|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp||In member function ‘virtual void MyAppli::onLoad()’:|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|97|erreur: no matching function for call to ‘sf::Sound::setBuffer(odfaeg::audio::Stream&)’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|97|note: candidate is:|
/usr/include/SFML/Audio/Sound.hpp|126|note: void sf::Sound::setBuffer(const sf::SoundBuffer&)|
/usr/include/SFML/Audio/Sound.hpp|126|note:   no known conversion for argument 1 from ‘odfaeg::audio::Stream’ to ‘const sf::SoundBuffer&’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|100|erreur: ‘class sf::Sound’ has no member named ‘setAudioStream’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp||In member function ‘virtual void MyAppli::onInit()’:|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|307|erreur: no matching function for call to ‘sf::Sound::play(bool)’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|307|note: candidate is:|
/usr/include/SFML/Audio/Sound.hpp|89|note: void sf::Sound::play()|
/usr/include/SFML/Audio/Sound.hpp|89|note:   candidate expects 0 arguments, 1 provided|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp||In member function ‘virtual void MyAppli::onUpdate(sf::Event&)’:|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|433|erreur: ‘class sf::Sound’ has no member named ‘isPlaying’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp||In member function ‘virtual void MyAppli::onExec()’:|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|452|erreur: ‘class sf::Sound’ has no member named ‘isPlaying’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|453|erreur: no matching function for call to ‘sf::Sound::play(bool)’|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|453|note: candidate is:|
/usr/include/SFML/Audio/Sound.hpp|89|note: void sf::Sound::play()|
/usr/include/SFML/Audio/Sound.hpp|89|note:   candidate expects 0 arguments, 1 provided|
/home/laurent/Développement/Projets-c++/ODFAEG-DEMO/application.cpp|490|erreur: ‘class sf::Sound’ has no member named ‘isPlaying’|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 5 second(s)) ===|

The player class doesn't do anything more than calling the methods play, stop, etc... of the SoundStream class.

It's fine but.

When I load another sound buffer with a second player, and when I play it, the first sound is stoped, so, the two sounds are not played at the same time.  :-\

Is it a bug, if it's already a reported issue, sorry about that. :/
But in the tutorial it is said that we can play serveral sounds at the same time, so, I don't understand that.

13
Network / [SFML2.2] Server not receiving. (Strange issue)
« on: December 17, 2014, 06:11:25 pm »
Hi!

I've a strange issue, it worked a few months ago, but here, since I've compiled the source code again, it doesn't work anymore. :/

I don't know if it's because of SFML or because of some ubuntu packages that I've installed recently.

When I send a message from my client to the serveur, the first message is well received, but, the next packets are empty.

sf::Socket::Done is well returned but my packet is empty.

And sometimes I get a buffer overflow error. :/

I use a thread to receive packets of course, because, I have to wait until a certain tomout is over, and I have to continue to check if a message is received withthout freezing the network loop until the timeout is over.

I think I'll backup everythink and re-install my OS..., it's certainly a bad c++ package or something like this.







14
Feature requests / Separating event generation and the window.
« on: November 15, 2014, 02:41:57 pm »
Hi, with SFML this is the window which produce events, but what if the application have no window.

We are forced to create an invisible window to get events and if we have multiple windows we are forced to call the pollEvent function twice instead of once.

You intend to manage multiple windows screens, so, I think it should be good to separate events generation and the window like SDL does.



15
Window / Bug with the keyboard ?
« on: November 06, 2014, 03:06:23 pm »
Hi, I'm actually coding a system which calls callback functions depending on which events are generated. (Or which keys or buttons are held down/pressed once)

When I have two keys pressed, and when I release only one, no more keypressed events are generated, even if a key is still pressed.

Is it a hardware bug or a SFML issue ?

PS : I'm on ubuntu.

Thanks.

Pages: [1] 2 3 4