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

Recent Posts

Pages: [1] 2 3 ... 10
1
Window / Failing to render anything
« Last post by szerokiG on Today at 06:56:27 pm »
Hello, I've been trying to make a SFML project and succeeded, however when trying to link a DLL to my project I stumbled upon a roadblock. Now trying to render ANYTHING somehow fails and I can't figure out why's that. Everything is linked correctly however SFML is acting in a VERY weird way.
Even the simplest:

this->m_window->clear();

Somehow fails. After a few seconds I get an exception:

Quote
Exception thrown at 0x00007FF95FA82A47 (igxelpicd64.dll) in MAIN.exe: 0xC0000005: Access violation writing location

Pls help.  :-\
2
I haven't read your OpenGL code, but if you use the default AlphaBlend blend mode, this is expect behavior.

You're rendering the same transparent item over the other, adds the alpha values, so over multiple iterations the alpha value simple gets to the max value and this becomes fully visible and not transparent anymore.
3
Make sure your E:\SFML-2.6.1\lib directory contains the needed files (e.g. libsfml-graphics-d.a).

Make sure the compiler is actually configured to the expected version.

I use the following download for SFML 2.6.1: "GCC 13.1.0 MinGW (DW2) - 32-bit".

I use the newest release of CB (installed from codeblocks-20.03mingw-32bit-setup.exe).
Those don't match, see the links in the red box on the SFML Download page, that links you to the exactly matching compiler.
4
General / Re: Font Loading.
« Last post by o2ciri on Today at 05:45:16 pm »
Ok, I tried pasting your code into my main and it worked. Also changing font* in the constructor to sf::Font font also works. Thanks for your help.

I'm also wondering how to initialize the font in the .h file to use it in the .cpp, since it should be initialized in the initializers of the constructor, and writing the loading from the file in the initializers, I'm not sure that's a good idea.
5
General / Re: Font Loading.
« Last post by eXpl0it3r on Today at 05:26:13 pm »
I didn't pay much attention to the specific code, but the culprit might be this: *font

You're dereferencing your pointer, but since you've never initialized it, you'll run into undefined behavior and it can crash.

Check your warning levels of the compiler, there might be a warning shown for this.
6
Graphics / Re: How expensive are sprites?
« Last post by dshenoy on Today at 04:04:55 pm »
@eXpl0it3r - Thank you ver much.  I’ll dig deeper into vertex arrays or buffers as you mentioned.

7
General / Re: Font Loading.
« Last post by eXpl0it3r on Today at 03:10:38 pm »
I can't reproduce it.

I've used VS2022 as well and the following CMake script and C++ code.

cmake_minimum_required(VERSION 3.22)
project(SFMLTest CXX)

include(FetchContent)
FetchContent_Declare(SFML
    GIT_REPOSITORY https://github.com/SFML/SFML.git
    GIT_TAG master)
FetchContent_MakeAvailable(SFML)

add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest PRIVATE SFML::Graphics)

#include <SFML/Graphics.hpp>

#include <iostream>

int main()
{
    auto window = sf::RenderWindow{sf::VideoMode{sf::Vector2u{500, 500}}, "SFML Test"};
    window.setVerticalSyncEnabled(true);

    auto font = sf::Font::loadFromFile(R"(C:\Windows\Fonts\Arial.ttf)");
    if (!font.has_value())
    {
        std::cerr << "Can&#39;t load font" << std::endl;
        return -1;
    }

    auto text = sf::Text{ *font, "Hello World" };

    while (window.isOpen())
    {
        while (auto event = window.pollEvent())
        {
            if (event.is<sf::Event::Closed>())
            {
                window.close();
            }
        }

        window.clear();
        window.draw(text);
        window.display();
    }
}

If you run it through a debugger do you see where it crashes?
If you check the Windows Event Log under Application, do you see more information there?
Is you application logic just so that the application closes? ;D
8
Graphics / Re: How expensive are sprites?
« Last post by eXpl0it3r on Today at 02:51:33 pm »
Sprite itself is a lightweight class and doesn't directly have an impact on performance.

The texture it uses and the draw calls made by the sprite is what needs to be considered.

If you use multiple textures, then you'll be paying the price of a texture context switch, which can be okay, but can also quickly add up. As such the general recommendation is to use texture atlases (e.g. tile maps), which then lets you reuse the same texture, but with a different texture rect.

Draw calls are slow and one of the most common causes for rendering performance issues (with SFML).
This should usually be fine for a few hundred sprites, if you get into the thousands, you should really reconsider your options. The general recommendation here is to switch to vertex array or vertex buffer, which allows you to render a whole "mesh" of vertices in a single draw call.

The best source (pun intended) for these questions is the source code: https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Graphics/Sprite.cpp

Are sprites stored on the GPU (ie all he details about the graphical icon)?
No, sprites reside entirely on the CPU/RAM side. Textures however are stored in VRAM (which is why copying textures is expensive, as you first have to move it from VRAM to RAM and then back to VRAM).

How do you judge whether you have too many sprites?
There isn't a specific rule. Usually things become noticeable if your game (not some artificial "benchmark") doesn't manage to get a reasonable framerate (60-200fps).

Is there context switching that takes place with spite data stored on the GPU?  Is it switching in and out from the CPU if there isn’t enough capacity?
[/quote]
Sprites are lightweight objects. You can use them even as temporaries and recreate them every frame, but just because you can, doesn't mean it's really recommended. ;)
9
Graphics / How expensive are sprites?
« Last post by dshenoy on Today at 02:25:43 pm »
Dear Community,

I’m running my code on a mac osx machine.  I’m trying to understand the details behind sprites.  I wanted to know the following:

  • Are sprites stored on the GPU (ie all he details about the graphical icon)?
  • How do you judge whether you have too many sprites?
  • Is there context switching that takes place with spite data stored on the GPU?  Is it switching in and out from the CPU if there isn’t enough capacity?

Please let me know if there are links on the internals for SFML sprites if they exist (advanced info)

Thanking you in advance.
10
General / Re: Font Loading.
« Last post by o2ciri on Today at 12:52:32 pm »
The font is not used in any way, it just loads and that's it.

Since I said above, the problem with mixing libraries goes away, the screenshots show how the built project looks like in VS2022:

Connected libraries for the build type:

Debug
dep\SFML\lib\Debug\sfml-graphics-s-d.lib;dep\SFML\lib\Debug\sfml-window-s-d.lib;dep\SFML\lib\Debug\sfml-system-s-d.lib;opengl32.lib;winmm.lib;gdi32. lib;D:\Projects\Ironforge\dep\SFML\extlibs\libs-msvc-universal\x64\freetype.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib
 

Release
dep\SFML\lib\Release\SFML\sfml-graphics-s.lib;dep\SFML\lib\Release\sfml-window-s.lib;dep\SFML\lib\Release\sfml-system-s.lib;opengl32.lib;winmm.lib;gdi32. lib;D:\Projects\Ironforge\dep\SFML\extlibs\libs-msvc-universal\x64\freetype.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib
 


Is 2560, 1440 a valid resolution for your monitor? Yeah, I take it this way:

int main()
{
    sf::VideoMode videoMode;
    videoMode.size.x = videoMode.getDesktopMode().size.x;
    videoMode.size.y = videoMode.getDesktopMode().size.y;

    Application application(videoMode);
    application.run();

    return 0;
}
 

Also u can see screenshot :)
Pages: [1] 2 3 ... 10