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

Pages: [1]
1
Graphics / Error opening window with Intel HD Graphics 3000
« on: July 27, 2023, 05:24:14 pm »
I have a laptop with a Intel HD Graphics 3000. When I try to run this code:
...
int main()
{
   sf::RenderWindow window(sf::VideoMode(1366, 768, "Window");

}
 

2
Audio / Re: Creating audio by pulling single samples
« on: July 27, 2021, 12:01:04 pm »
Yeah thought so. Thanks again.

3
Audio / Re: Creating audio by pulling single samples
« on: July 27, 2021, 11:12:02 am »
Yep that's exactly what I wanted. I am now keeping track of a vriable virtualTime and increment it everytime I create a new sample by 1/sample_rate, just like you said.

I noticed when I create a new sf::Int16 array each time the function gets called, there is some noise between the sample chunks. But this problem stopped being a problem when making the array a member of the class and not a temporary. I guess this had something to do with the fact that a pointer is passed to the Chunk and the underlying data was released before it could be copied.

Thank you very much!

4
Audio / Creating audio by pulling single samples
« on: July 26, 2021, 03:09:29 pm »
Hello,

I am trying to create an audio on the fly. I want a sound to be playing and while that happens new audio samples should be pulled from a function.
I have looked at the sf::SoundStream class. But this requires you to push back a few thousand new samples each time onGetData(Chunk& data) gets called. I want to provide only 1 sample. The function onGetData should look something like this:

sf::Int16 pullSample()
{
    return 1000 * std::sin(currentTime * ...);
}

I know that this requires with a sample rate of 44100, 44100 calls to that function each second. Is this still somehow possible or are there other work-arounds?

5
Graphics / Re: LoadFromFile fails after too many sf::Text objects
« on: March 29, 2021, 04:14:23 pm »
Quote
Why are you trying to load 1000 times the same font?
I am creating a list as a user interface where each list element consists of multiple text objects. That list gets quite large also because I have 4 lists in total (and some other locations were I load fonts). For example 80 list elements each loading 2 fonts creates 160 font objects.

Quote
Said differently, you can reuse the font object for multiple text objects.
That will fix the problem. I am just creating to many font objects. I'll try to implement that.

Thank you for your replies.

6
Graphics / LoadFromFile fails after too many Text objects
« on: March 28, 2021, 08:02:54 pm »
I am trying to create 1000 sf::Text objects. But loadFromFile returns 0 after 508 initialized objects. Why is that the case and is there a way to by pass this to create all 1000 objects? The code example demonstrates this.

Thank you for your time.

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

class Text
{
private:
    sf::Text text;
    sf::Font font;

    sf::RenderTarget& renderTarget;
public:
    Text(const sf::String& fontPath, sf::RenderTarget& p_renderTarget) : renderTarget(p_renderTarget)
    {
        std::cout << "Font loaded: " << font.loadFromFile(fontPath) << std::endl;
        text.setFont(font);
        text.setString("Hallo Welt!");
        text.setCharacterSize(25);
    }

    void Update() { renderTarget.draw(text); }
};

int main()
{
    sf::RenderWindow window(sf::VideoMode(900, 600), "SFML works!");
    std::vector<Text*> texts;
    int textAmount = 1000;
    for (int i = 0; i < textAmount; i++)
    {
        std::cout << "Nr." << i << ": ";
        Text* t = new Text("arial.ttf", window);
        texts.push_back(t);
    }

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

        window.clear();
        for (int i = 0; i < textAmount; i++)
        {
            texts[i]->Update();
        }
        window.display();
    }

    for (int i = 0; i < textAmount; i++)
    {
        delete texts[i];
    }
}

7
Nevermind your right. Sänks very much

8
But the sprite position is always (0,0) or am I missunderstanding something? You would need to subtract the distance to the original position(of the renderTexture) from the mouse position, but there is no way to calculate that distance. Just by keeping track yourself on how you moved the sprite(meaning the renderTexture), but that's annoying.

9
I want to check if my mouse is over a shape inside a renderTexture. The problem: shape.GetGlobalBounds is relative to the renderTexture, whereas the mouse positon is relative to the window. I don't know how to make both relative to the same origin. So how would I check a collision between mouse and shape?

Thanks for any help 8)

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

int main()
{
        sf::RenderWindow window(sf::VideoMode(900, 600), "Title");

        sf::CircleShape circle(50.f);
        circle.setPosition(0.f, 0.f);
        circle.setFillColor(sf::Color::Red);

        sf::RenderTexture rTexture;
        rTexture.create(400.f, 400.f);
        sf::Sprite sprite;
        sf::Texture texture;

        sprite.move(100.f, 100.f);

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

                rTexture.clear(sf::Color::Blue);
                rTexture.draw(circle);
                rTexture.display();

                texture = rTexture.getTexture();
                sprite.setTexture(texture);
               
                window.clear();
                window.draw(sprite);

                if (circle.getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window)))) /*Mouse positon is relative to window -> returns (100,100) when getGlobalBounds returns (0,0)*/
                        circle.setFillColor(sf::Color::White);
                else circle.setFillColor(sf::Color::Red);

                std::cout << circle.getGlobalBounds().left << " " << circle.getGlobalBounds().top << std::endl;

                window.display();
        }
}
 

Pages: [1]
anything