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

Pages: [1] 2
1
Audio / Re: Playing sound at volume above 100
« on: May 30, 2022, 02:39:26 pm »
I needed to amplify too quiet sounds without using the Audacity.
So just to conclude.

You CAN pass a volume value greater than 100.
The OpenAL implementation clips too high values forcing them to be in the int16 range obviously.
So if you don't want the sound to be overloaded, the actual max volume value for a specific sound depends on the max sample values. E.g. having max absolute sample value equal to 3276 you can pass volume value up to 32767 / 3276 * 100 = 1000 (where 32767 is the max positive int16).

There are many ways to check the sample values, e.g. you can use the sf::SoundBuffer class to get samples.
I personally used a Python script like that:

import pyogg

ogg_file = pyogg.VorbisFile(file_path)
buffer = ogg_file.as_array()
print(buffer.min(), buffer.max())


P.S. Sorry for posting into a thread which is several years old.

2
Graphics / [SOLVED] Re: setVerticalSyncEnabled is broken in 2.5.0?
« on: August 22, 2018, 12:47:22 am »
Indeed, if there is a call from non-main thread, this call is ignored on Windows. And on Linux it causes that all subsequent calls do not work.

3
Graphics / Re: setVerticalSyncEnabled is broken in 2.5.0?
« on: August 22, 2018, 12:11:27 am »
I have written a simple example. However it does not reproduce the issue.
However I realized that the very first call is done from a non-main thread, when the app is reading preferences and other stuff. I guess this might cause the issue?

(click to show/hide)

4
Graphics / Re: RenderTexture is invisible on Android
« on: August 21, 2018, 10:10:25 pm »
The issue seems to be fixed in SFML 2.5.0.

5
Graphics / [SOLVED] setVerticalSyncEnabled is broken in 2.5.0?
« on: August 21, 2018, 10:08:24 pm »
Hi there,

I just migrated to 2.5.0 and suddenly realized that the FPS is not limited, it does not matter whether verticalSyncEnabled is set to true or false.
Tested on Windows and Linux.
Is it something known?

Update. On Windows, the first call setVerticalSyncEnabled(true) does nothing, however, subsequent calls setVerticalSyncEnabled(false) and setVerticalSyncEnabled(true) lead to the desired effect.

6
General discussions / Common mistakes
« on: March 23, 2018, 07:51:08 am »
As far as I can see there is a set of common mistakes done when writing SFML based applications.
Is there a page describing the most common of them? If there is no, it is probably a good idea to gather explanations in a single place. Then it'll be possible to simply reply with a reference to a corresponding section.

These are the most common AFAICS:

- static SFML object initialization
- referring to a destroyed object
- not handling events
- drawing once out of the main loop
etc.

Let's list more in comments.

7
Graphics / Re: Window opens then closes really fast
« on: March 23, 2018, 07:40:52 am »
Your print function returns a text object which refers to a font object. However the font object lifetime is limited to the print function, it it destroyed as soon as the function returns. So in the main function the just returned text refers to a non-existing font object. This  leads to undefined behavior (e.g. to a program crash).

To solve the issue you may pass the font defined in the main function into the print function. Like this:
sf::Text print(const std::string& text, const sf::Font& font); // Use the font inside

Probably you should learn about C++ objects lifetime and about passing parameters by reference :)

8
Graphics / [CLOSED] RenderTexture is invisible on Android
« on: March 14, 2018, 08:48:30 pm »
Hi!

On one of my Android devices (Lenovo K10a40, Android 6.0) a RenderTexture is not displayed on the screen. At all.
The following minimal example is enough to reproduce the issue:
Quote
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main(int argc, char* argv[])
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window", sf::Style::Fullscreen);
    sf::RenderTexture texture;
    if (!texture.create(500, 500))
        return -1;

    sf::CircleShape shape(50);
    shape.setFillColor(sf::Color::White);

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

            if (event.type == sf::Event::Resized)
            {
                sf::Vector2f size(
                    static_cast<float>(event.size.width),
                    static_cast<float>(event.size.height));
                window.setView({{}, size});
            }
        }

        texture.clear(sf::Color::Red);
        texture.draw(shape);
        texture.display();

        window.clear();
        window.draw(shape); // visible
        window.draw(sf::Sprite(texture.getTexture())); // invisible
        window.display();
    }
}

The code is almost the same as in the reference: https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1RenderTexture.php.
I have added an extra draw call to put the shape below the texture, it is visible as if there were no anything else. So there is just a circle on a black screen.

What can be wrong?

9
So where does the segfault happen? There are no any comments in your code.

10
General / Re: Could not find OpenAL while cmaking Android on Windows 10
« on: February 21, 2018, 07:01:51 pm »
No ideas?
I've decided to build SFML using Android Studio CMake and even succeeded in that.
But I'm still curious what's happened there.

11
General / Re: Image of Sprite Skipping on Screen
« on: February 17, 2018, 11:57:14 am »
For this code:
Quote
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main() {

   sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);

   //window.setVerticalSyncEnabled(true);
   //window.setFramerateLimit(144);
   //window.setFramerateLimit(60);

   int refresh_rate = 60;

   // Background //
   sf::Texture background;
   if (!background.loadFromFile("stars_square.png"))
      exit(1);
   background.setRepeated(true);

   sf::Sprite stars(background);

   float posx = 0;
   float currentspeed = 0;
   float picture_speed = 30;
   // ---------- //

   sf::Clock clock;
   float current_time = clock.getElapsedTime().asSeconds();
   float frame_time = 0;

   while ( window.isOpen() ) {

      sf::Event event;
      while (window.pollEvent(event)) {
         switch (event.type)
         {
            case sf::Event::Closed:
               window.close();
               break;
            case sf::Event::Resized:
               window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
               break;
               
         }
      }

      float new_time = clock.getElapsedTime().asSeconds();
      frame_time = new_time - current_time;
      current_time = new_time;

      stars.setPosition(posx, 0);

      posx = std::fmod(posx + (picture_speed * frame_time), background.getSize().x);

      window.clear();
      window.draw(stars);
      window.display();

   }

}

You wrote:
Quote
Still produces the same skipping.

But the move direction is different from original. The stars here do not cover the whole screen. This makes me unsure.
The following is obviously missing in the code (setting the texture rect to make it larger than the texture and setting the origin to make the sprite covering the whole screen when it moves right):
Quote
    stars.setTextureRect({
        0,
        0,
        2 * window.getSize().x,
        2 * window.getSize().y});
    stars.setOrigin(window.getSize().x, 0);

Unfortunately I cannot load the proof videos, so you have to believe :)

12
General / Re: Problem with drawing text from inherited class
« on: February 16, 2018, 09:14:54 pm »
From the code you have posted it is only clear that you do not call cap.setString(caption) inside your button constructor.
If you do that somewhere else, please also post the code which initializes the button.

NB. I would also recommend you to read about C++ virtual functions and function overloading.

13
Graphics / Re: Vertical line artifacts in simple image
« on: February 16, 2018, 08:13:15 am »
A screenshot, please?

14
Graphics / Re: Any way to decrease text rendering time ?
« on: February 16, 2018, 08:08:15 am »
Do you draw the text just once and then exit in your test? Most of SFML classes use caching and lazy initialization, so the second and subsequent draw calls are usually significantly faster.

15
General / Re: Declaring sf::Font and sf::Color in a header
« on: February 16, 2018, 07:46:47 am »
Quote
Then I define them in the beginning of my main() like so:
Since the variables are defined inside a function, they are not global. So they are not visible outside of the main() function.
Put the definitions at the .cpp file level to make them accessible through 'external' declarations.

Pages: [1] 2