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

Recent Posts

Pages: [1] 2 3 ... 10
SFML projects / Re: A.I. Chatbot + 2D space exploration game!
« Last post by mrzo on Today at 01:40:41 am »
Some people asked me on other channels how the actual gameplay looks like so I made an extra trailer showing it.


In general, you can decide how to steer your space ship: completely by yourself or by using the A.I. assistant. The same is valid for combat. You can ask the A.I. to take over the weapons and put it either in defensive mode (only firing at hostile missiles) or aggressive mode (attacking hostile ships directly). Or - if you feel like it - you can take control of the guns and fire at your will.
Hm, judging from you mentioning the future developer, did you perhaps interpret that I'm suggesting to elaborate on the comments in the implementation file, https://github.com/SFML/SFML/blob/master/src/SFML/Window/Unix/InputImpl.cpp ? Because that actually wasn't my idea, but rather to hint the user of SFML that sf::Mouse::isButtonPressed won't work for the extra buttons in Linux. So I think that comment would go right into the mouse header, https://github.com/SFML/SFML/blob/master/include/SFML/Window/Mouse.hpp.
General / Re: Efficient way to draw and get pixels
« Last post by Stauricus on January 28, 2022, 12:32:26 pm »
moving GPU to CPU is always slow, unfortunately.
but in this case you could try an OpenGL function, like glReadPixels.

unsigned char data[4];
glReadPixels(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data);
General / Efficient way to draw and get pixels
« Last post by karagal on January 28, 2022, 11:32:43 am »

I have been using SFML to render a driving simulator in C++, which is interfaced to Python using pybind11 for a deep learning project. At each frame I am drawing to a render texture, updating it, copying it to an image, getting the unsigned char pixel array (80*80*4), and copying it into a vector which I then return (I'm copying it to a vector so that the pixels can be moved to Python without copy). Right now this happens about 1000 times per second and is quite slow.

I'm coming here to see if anyone sees a more efficient way to do this, or if SFML is just not the right library for this task. Is there a way to avoid that costly GPU-to-CPU operation? (I just want the pixels, not to render to the screen, but I'm not sure it changes anything).

Thanks! :)
Graphics / Re: SFML how to draw a line
« Last post by Hapax on January 27, 2022, 10:17:27 pm »
I presume this is a line with thickness.

As mentioned in the SFML tutorials, a line is just two vertices in a vertex array or - if it has thickness - a rectangle.

That said, positioning that rectangle can be a little tricky.
So, if you need a line with thickness, consider using Selba Ward. It is a collection of SFML drawables that can be used/included independently of each other.
It includes a simple Line object that you can use to create lines with (or without) thickness including adding texture to them as well as keeping the interface you are used to with SFML.
It also includes Spline that you can use to create "polylines" - multiple lines connected end-to-end. It can create Bezier curves. Again, this can have thickness or none - including changing thickness along the spline itself. Have a look at Selba Ward's SFML forum thread here and look at some examples ;)

There are other objects there too, ranging from extremely simple (like Line, for example) to extremely complex (for example, Console Screen).
View Selba Ward's wiki to see the full list. Pick and choose what you like  :)
Audio / Re: In implementation of MyStream sound sometimes doesn't play
« Last post by GetterSetter on January 26, 2022, 06:42:31 pm »
Ok, I found the similiar problem on SO (i guess): https://stackoverflow.com/a/62172120
I've compiled new SFML release and the output is:
An internal OpenAL call failed in SoundStream.cpp(448).
   alBufferData(buffer, m_format, data.samples, size, static_cast<ALsizei>(m_sampleRate))
Error description:
   A numeric argument is out of range.

And the solution was:
samplesToStream -= samplesToStream % 4;
Graphics / Re: [SOLVED] OpenGL oddness
« Last post by short_name on January 26, 2022, 02:09:55 am »
Realized I shouldn't be mixing glut with sfml
Graphics / [SOLVED] OpenGL oddness
« Last post by short_name on January 26, 2022, 12:54:52 am »
The below code results in a greyscale grid of spheres rather than the ywllow spheres I expected to see. If I uncomment the lines:

  //sf::Text testtext;
  //testtext.setString("HELLO OPENGL");

Then the spheres turn yellow. but something is still off about the depth testing. The spheres on the left side of the window look correct but the ones on the right side are being rendered in the wrong order.

Anyone see what mistake(s) I am making?

#include <SFML/Graphics.hpp>
#include <math.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

int main(int argc, char **argv) {
  sf::RenderWindow window( sf::VideoMode(800,600,32), "SFML + OpenGL" );
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  GLfloat lightpos[] = { 55.0, 55.0, -55.0 };
  GLfloat lightcolor[] = { 1.0, 1.0, 0.0 };
  GLfloat ambcolor[] = { 0.0, 0.0, 1.0 };

  //sf::Text testtext;
  //testtext.setString("HELLO OPENGL");

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

    gluPerspective(50.0, 1.0, 1.0, 70.0);
    gluLookAt( 0.0, 1.0, 5.0,
               0.0, 1.0, 4.0,
               0.0, 1.0, 0.0);

    //draw the spheres
    glColor3f(0.4f, 0.4f, 0.4f);
    int h = 10;
    for( int i = -h ; i <= h ; i++ )
      for( int j = -h ; j <= h ; j++ )

  return 1;

Audio / In implementation of MyStream sound sometimes doesn't play
« Last post by GetterSetter on January 25, 2022, 11:38:24 am »
I got the code from https://www.sfml-dev.org/tutorials/2.5/audio-streams.php and replaced
const int samplesToStream = 50000;
const int samplesToStream = getSampleRate()/factor;
It worked fine until factor was 4 (or 4^k: 4,16,64...). In case if factor == 4^k, sound doesn't play and the app closes immediately with no errors
#include <SFML/Audio.hpp>
#include <vector>

// custom audio stream that plays a loaded buffer
class MyStream : public sf::SoundStream

    void load(const sf::SoundBuffer& buffer)
        // 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
        initialize(buffer.getChannelCount(), buffer.getSampleRate());


    virtual bool onGetData(Chunk& data)
        // number of samples to stream every time the function is called;
        // in a more robust implementation, it should be a fixed
        // amount of time rather than an arbitrary number of samples
        const std::size_t samplesToStream = getSampleRate()/4;

        // 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;
            // 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;

    virtual void 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());

    std::vector<sf::Int16> m_samples;
    std::size_t m_currentSample;

int main()
    // load an audio buffer from a sound file
    sf::SoundBuffer buffer;

    // initialize and play our custom stream
    MyStream stream;

    // let it play until it is finished
    while (stream.getStatus() == MyStream::Playing)

    return 0;
OS: Ubuntu 20.04.3 LTS
SFML version: 2.5.1
General / Re: SFML Game Development By Example, Utilities.h problem
« Last post by eXpl0it3r on January 25, 2022, 08:11:23 am »
This is the SFML forum, I suggest to post to StackOverflow or similar for pure C++/WinAPI questions, you'll most likely get answers quicker.
Pages: [1] 2 3 ... 10