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

Pages: [1]
Graphics / Issue with sf::View and pixel perfect texCoords
« on: May 11, 2018, 01:19:57 am »
Hello there.

After introducing scrolling via sf::View to a tile based scene, I discovered sporadic occurence of artifacts. It took me a while to find the source via experimenting a lot but now I have come to the conclusion that occasionally, my View is set in such an unfortunate way that some transformations cause additional pixels to be drawn.

A bit more detailed:

I've got a bunch of Tiles using Quads with texCoords which are a multiple of some integer tile size referring to a tilemap texture. I made sure that the float values actually are integers. Something like [0, 0], [0, 16], [16, 0], [16,16] and the likes.

Now, I set the View every frame before drawing and occasionally tiles are drawn with pixels that belong to the next tile on the texture (like [17, 16] instead of [16, 16] for the bottom right pixel). Generally, those additional pixels are completely unrelated thus leading to artifacts.

Do you have any ideas from preventing this to happen?

I think the problem does not occur if I set the View's top left corner as an integer. However, this causes other problems because my View follows some Sprite with float (actually double) position (resulting in serious jittering). Or I might convert all the positions to integer for drawing (but this might also be a problem because of rounding issues).

Or shall I try setting the tex coords to the center of the pixels (like [0.5, 15.5])? Sounds off to me.

Graphics / Qt & SFML in 2.4
« on: February 09, 2018, 05:57:29 pm »
Hello there.

I am afraid that this problem might be very difficult to solve because I can barely give you any information, but maybe you have got an idea on how to solve it.

Quite a while ago, I successfully managed to integrate SFML into Qt (see https://en.sfml-dev.org/forums/index.php?topic=19163.msg138596#msg138596 and https://github.com/SFML/SFML/blob/master/src/SFML/Window/Unix/WindowImplX11.cpp).

I did it on Windows (MinGW), SFML 2.3.2, but it also worked on linux (g++).

Currently, I am working on linux. I compiled SFML 2.4 for myself with Clang. Now, when I start my Qt/SFML application, as soon as the GUI shows up, I get the error message
Failed to create input context for window -- TextEntered event won't be able to return unicode
exactly once, while I have two QWidget/sf::RenderWindow elements.

Edit: Actually, I found out that this happens once for every second QWidget/sf::RenderWindow element I add, which is very odd (or rather: even).

The application continues to run
, however, the contents of those windows are not positioned correctly and the proportions are off. properly without any issues.

I tried debugging but I cannot find out at which point the problem arises. I think it is somehow triggered by Qt when it starts displaying the application gui. Still, I do not think I changed anything of the window creation process since I worked with the older SFML version, so I wonder if something in the new SFML version changed the behavior.

Unfortunately, I cannot provide any minimal example code (as I cannot narrow down the problem's origin), but I can show you my Qt/sf::RenderWindow implementation class, which I attach to this post.

I also welcome general ideas on when the error message mentioned above can occur.

General / Game Loop Lag
« on: December 11, 2017, 07:39:05 pm »
Hello there.

Does anyone see what mistake I made in my game loop? I thought it to be a standard approach, yet I get a periodic micro-lag roughly every second.

I have already played around with various things like integer positions, sleeping for some milliseconds, enabling v-sync, drawing in a separate thread, interpolating the movement. Yet it must be some different problem as nothing helped so far.

Minimal example (for better readability, all the variables are declared in the beginning):

#include "SFML/Graphics.hpp"

const int FPS = 60; // frames per second
const double SPF = 1.0/FPS; // seconds per frame
const double MSPF = 1000.0/FPS; // milliseconds per frame

bool quit = false; // quit flag

sf::Clock timer; // timer to measure lapsed time
int delay = 0;  // delay to determine when to update physics
int carry = 0; // leftover of delay from last update

// object to be drawn
sf::RectangleShape rect = sf::RectangleShape(sf::Vector2f(200, 200));
double rectSpeed = 200;
double x = 0;

// physics update
void update() {
    x += rectSpeed*SPF;
    while(x > 1200) {
        x -= 1400;
    rect.setPosition(x, 0);

// draw to screen
void draw(sf::RenderWindow &window) {

int main()
    sf::RenderWindow window(sf::VideoMode(1200, 900), "Test");

    carry = 0;

    while(quit == false) {
        sf::Event event;
        while(window.pollEvent(event)) {
            if(event.type == sf::Event::Closed) {
                quit = true;
        delay = carry + timer.getElapsedTime().asMilliseconds();
        if(delay >= MSPF) {
            while(delay >= MSPF) {
                delay -= MSPF;
            carry = delay;
    return 0;



Hey there.

Until now, I used a RenderWindow to draw my scene and manually moved it by applying a transition to the scene (which inherits from Drawable). However, apparently SFML provides the View class.

Now I wonder what kind of RenderTarget I should pick to draw my whole, possibly very large scene. RenderWindow seems to be unfit as this seems to be supposed not to be bigger than an actual display screen. Now there's also the RenderTarget base class and a RenderTexture class. I really can't figure out what to pick! I also think that there must be kind of a GPU limit to the dimensions.

If that's important: I draw into a Qt window and the only way to integrate I know is https://github.com/SFML/SFML/wiki/Tutorial%3A-Integrating-SFML-into-Qt , which uses a RenderWindow object.

SFML wiki / Tutorial: Integrating SFML into Qt: FrameTime = 0
« on: July 15, 2016, 09:15:35 pm »
Hi there.

Regarding https://github.com/SFML/SFML/wiki/Tutorial%3A-Integrating-SFML-into-Qt , I think one could suggest changing the constructor
QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);
such that default value is
unsigned int FrameTime = 1000/frames_per_second
or something alike.

The reason is that with a zero FrameTime, at least in my case (Windows 7), the program uses a whole lot of CPU time without actually doing anything. Changing it to a value like 1000/60 drastically reduces the CPU usage, and 60fps should be really enough for drawing in a GUI.

If you agree, you could update the tutorial (I won't as I don't want to register there), however, if my suggestion is not reasonable, please explain.

General / [SOLVED] SFML inside QT: sf::RenderWindow and QScrollArea
« on: July 15, 2016, 03:52:46 pm »
Hey there.

Last year, I asked for help as I wanted to integrate SFML into QT. The post can be found here: http://en.sfml-dev.org/forums/index.php?topic=19163.msg138596#msg138596
We kind of concluded a way to do this and someone wrote it down as a tutorial here: https://github.com/SFML/SFML/wiki/Tutorial%3A-Integrating-SFML-into-Qt

My QWidget, which also is a sf::RenderWindow at the same time, is inside of a QScrollArea. If the QWidget/sf::RenderWindow is bigger than the QScrollArea, scrollbars appear and behave as expected.

However, I want to draw a really big object (multiple displays in size). I figure that the solution is not to set the QWidget/sf::RenderWindow that big (you usually don't have windows bigger than your screen can display).

I think I know how to implement a RenderWindow that only shows a portion of the object and scrolling by translating the object relatively. However, as the QWidget/sf::RenderWindow now is only as big as the actually seen portion, the QScrollArea around it doesn't need to provide any scrollbars as the object insinde fits into it.

So I wonder if there is a way to tell the QScrollArea that the size of the QObject/sf::RenderWindow inside is actually bigger (as big as the object I want to draw) without having the RenderWindow explode in size. If I found a way to do this, I guess I could connect the scrollBar to a function that perfoms the relative translation of the drawn object inside the RenderWindow.

Does this make any sense to you? It seems to be rather a Qt than a SFML question, but in my opinion it is of interest to everyone who wants to integrate SFML into Qt. If someone found a comprehensive way to achieve this, it could be added to the tutorial I mentioned above. I think that without this, integration is not fully achieved yet.

General / [SOLVED] Using SMFL for drawing into a Qt Widget
« on: October 19, 2015, 03:50:57 pm »
Hey there.

So I'm about to write an application using Qt Widgets and want to draw using SMFL 2.3.2. I'v stumbled upon


but it seems to be a bit outdated. Apparently, the functions Create() and Display() were changed to lower-case. So after adjusting this, the compiler (MinGW) says that the reference to "create" is ambiguous, referencing the line "create(winId());" inside the function void QSFMLCanvas::showEvent(QShowEvent*).

I haven't used Qt before and only tried very basic things with SMFL, hence I do not know how to handle this.

I would be very grateful if someone could help me with this so I can actually begin with what I have in mind.

Pages: [1]