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

Pages: [1] 2 3 4
1
General / How to build SFML on linux with a custom build folder?
« on: September 08, 2021, 09:46:32 pm »
The guide for building SFML with cmake https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php seems to be focused on Windows.

What I've tried so far:

$ cmake ./build
CMake Error: The source directory "/home/ingmar/src/SFML/build" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

$ mkdir build
$ cmake ./build
CMake Error: The source directory "/home/ingmar/src/SFML/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

Should I just just move CMakeLists.txt to build? Will pathes in there still be correct?

Running cmake . does work, but the guide explicitly suggest to specify a build folder. How do I do that?

2
Window / sf::Mouse::isButtonPressed returns always false for XButtons
« on: September 04, 2021, 06:45:03 pm »
Consider this minimal example to reproduce the problem:

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "test");

    sf::Event event;

    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::MouseButtonPressed:
                    switch (event.mouseButton.button)
                    {
                        case sf::Mouse::XButton1:
                        case sf::Mouse::XButton2:
                        case sf::Mouse::Left:
                            if (sf::Mouse::isButtonPressed(sf::Mouse::XButton1))
                                std::cout << "XButton1 pressed" << std::endl;
                            else if (sf::Mouse::isButtonPressed(sf::Mouse::XButton2))
                                std::cout << "XButton2 pressed" << std::endl;
                            else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                                std::cout << "Left button pressed" << std::endl;
                            else
                                std::cout << "No button pressed" << std::endl;
                            break;
                        default:
                            break;
                    }
                    break;
            }
        }
    }
}
 

The event for the XButtons is fired, yet sf::Mouse::isButtonPressed returns false; the output is "No button pressed". The problem doesn't occur for the left mouse button, the output is as expected "Left button pressed".

Have I found a bug? Or is there something funny with my mouse? Tested on Ubuntu 20.04.

3
Window / [SOLVED] Prolonged key press timeout
« on: August 30, 2021, 07:53:59 pm »
When pressing a key an Event is fired for that key being pressed. After that there is a timeout, in which no Event is fired for the same key still being pressed. The timeout seems to be about one second. After the timeout an Event is fired every frame.

Is it possible to control the lenght of this timeout, setting it to 0? Or is it possible to simply disable the timeout?

4
Ok, I decided to add that portion to the background to give the text a little frame:

sf::FloatRect bounds = text.getLocalBounds();
sf::Vector2f size(bounds.left * 2 + bounds.width, bounds.top * 2 + bounds.height);
sf::RectangleShape background(size);

Just out of curiosity, what is the reason for there being a hidden offset in sf::Text?

5
Graphics / How to interpret the local bounds .getLocalBounds() of sf::Text?
« on: November 10, 2020, 10:19:54 pm »
I'm drawing a background sf::RectangleShape for a sf::Text. After setting the Font, CharacterSize and the String I ask for its local bounds, to initialize the background rectangle:

sf::FloatRect textSize = text.getLocalBounds();
sf::RectangleShape background(sf::Vector2f(textSize.width, textSize.height));

Both the sf::Text and the sf::RectangleShape have the same position. But the background rectangle is always a little bit too small for the text. Top and Left are OK, but at the Bottom and the Right the text sticks out of the background rectangle.

Why is that so? What can I do about it?

6
Window / Re: How to select a Sprite from Mouse position?
« on: June 26, 2020, 09:01:22 pm »
Thanks for the hint to Window::mapPixelToCoords().

I did use getGlobalBounds on the Sprites, but upon further investigation I realized that the Sprites I had drawn and the Sprites I called getGlobalBounds on were not the same instances. I'm using pointers now and all is good!

7
Window / [SOLVED] How to select a Sprite from Mouse position?
« on: June 26, 2020, 02:20:56 am »
This is basically what I'm doing:

auto mouse = sf::Mouse::getPosition(window);
if (sprite.getGlobalBounds().contains(mouse.x, mouse.y))
    ...
 

That doesn't work as expected. A few issues arose:

1. The sprite's global bounds rect left/top is ALWAYS 0:0, although its position is not. Is this the expected behaviour?

2. sf::Mouse::getPosition(sf::Window&) doesn't respect position of the View, it seems to be the same as  sf::Mouse::getPosition(). I'm running in Fullscreen.

No I guess I could get the game world mouse position by adding the View position manually. And maybe if I set left/top to the position of the Sprite I could ask if it contains the mouse then.

But before trying this, I want to ask: What is the canonical way to get the Sprite under the mouse given my scenario with a game world much bigger than the desktop?

8
Graphics / Re: How to move the View?
« on: June 20, 2020, 12:57:17 am »
Thanks, especially for the link to the tutorial. That was very helpful.

9
Graphics / Re: How to move the View?
« on: June 19, 2020, 11:02:18 pm »
What do you mean by "Get your sf::View as a variable"?

The View from Window via getView()? Or do you mean a fresh View? How would I initialize that?

Everytime I move the View I have to set it with setView? Or can I move the view as much as I want once I've set it?


Edit:
I've tried setting a new View, but the Image is distorted.

I think that the default View in Window somehow gets initialized to my Desktop resolution (I'm running in fullscreen), but a new View gets some default resolution, resulting in a distorted Image. Initializing the View with the viewport from the view from window also didn't help.

10
Graphics / [SOLVED] How to move the View?
« on: June 19, 2020, 07:50:27 pm »
window.getView().move(0, 1);

doesn't work, because Window::getView is const, while View::move isn't.

How am I supposed to move the View?

11
Graphics / Is Sprite::setTexture() a heavy operation?
« on: May 10, 2020, 12:29:13 am »
Should I implement some sort of check if my sprite already has the right texture set?
Or is there no overhead if I set the same texture again and again in the game loop?

12
General discussions / Animated GIFs in SFML
« on: May 04, 2020, 09:47:41 pm »
Hi all,

I made a small class to display AnimatedGIFs in SFML:

https://github.com/SFML/SFML/wiki/Source:-Animated-GIF

Let me know what you think.

13
Window / Re: Is a call to window.isOpen() required to see anything?
« on: November 21, 2019, 01:46:51 am »
I received an error when I was trying to post my question, something about setAuthor. I tried a few times. So they all came through, albeit the error? Sorry about that.

I've send Laurent a message about it quoting the error.


Back to my question: When I replace usleep with just:

    sf::Event event;
    window.waitEvent(event);
 

I don't see the picture either.

14
Window / Is a call to window.isOpen() required to see anything?
« on: November 21, 2019, 01:00:10 am »
I've written minimal program to display an image:

int main()
{
    sf::Texture texture;
    texture.loadFromFile("foo.jpg");
    sf::Sprite sprite(texture);

    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "foo");
    window.draw(sprite);
    window.display();

    usleep(1000000);

    return EXIT_SUCCESS;
}
 

This doesn't display anything. Of course, when I replace usleep with:

    sf::Event event;

    while (window.isOpen())
    {
        window.waitEvent(event);
    }
 

I can see my picture. However, when I omit the call to window.waitEvent(), I don't see anything again. Calling only window.waitEvent(), not inside the window.isOpen() loop, doesn't display anything either.

My question is why? Is window.isOpen() or window.waitEvent() doing something hidden in the background that is neccessary to display anything?

15
General / Re: How to load images in a dedicated thread?
« on: January 01, 2014, 05:22:20 pm »
I've implemented a class to load textures asynchronously. But that resulted in the following error:
Code: [Select]
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
imani: xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)

Thus, to load textures asynchronously, i'de need to call XInitThreads() first. However, if i'm getting Laurents comment on this thread (http://en.sfml-dev.org/forums/index.php?topic=3138.0) right, this solution wouldn't be portable.

I therefore decided to only load the Images asynchronously and creating a texture for them in the main program. That did the trick. The overhead to load the images to the graphics card memory seems to be negligible.

In case anybody would like to see a working example, here comes my implementation:
Code: [Select]
ImageLoader.h

#include <future>
#include <SFML/Graphics.hpp>

class ImageLoader
{
    private:
        sf::Image *image;
        std::future<int> future;
        std::vector<std::string> pictureNames;

        int parallelMethod(void);

    public:
        ImageLoader(const std::string&);
        void launch(void);
        sf::Image* getImage(void);
};

ImageLoader.cc:

#include "ImageLoader.h"
#include "FileHelper.h"

ImageLoader::ImageLoader(const std::string &dir)
{
    pictureNames = FileHelper::loadFilenames(dir);
}

int
ImageLoader::parallelMethod()
{
    image = new sf::Image();
    while (image->loadFromFile(pictureNames[rand() % pictureNames.size()]) == false);
    return 0;
}

void
ImageLoader::launch()
{
    future = std::async(std::launch::async, &ImageLoader::parallelMethod, this);
}

sf::Image*
ImageLoader::getImage()
{
    future.wait();
    return image;
}

Pages: [1] 2 3 4