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

Pages: [1]
1
General / Re: Font Loading.
« on: May 31, 2024, 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.

2
General / Re: Font Loading.
« on: May 31, 2024, 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 :)

3
General / Re: Font Loading.
« on: May 31, 2024, 12:25:00 pm »
Yes, i tried to use many other fonts.

After I changed code this way:
Application::Application(sf::VideoMode videoMode)
    : window(videoMode, APP_TITLE, sf::Style::None, sf::State::Fullscreen)
{
    WindowManager::getInstance().setWindow(&window);
    try
    {
    *font = sf::Font::loadFromFile("resources/fonts/Cthulhumbus.ttf").value();
    }
    catch(std::exception& e)
    {
        std::cerr << e.what();
    }

}
 

I still don't get any message in my console.

Maybe not relevant to the problem, but I'm also getting the error:

.\Ironforge.exe
The requested video mode is not available, switching to a valid mode
  VideoMode: { size: { 2560, 1440 }, bitsPerPixel: 32 }
Failed to change display mode for fullscreen
 

But the font problem, I never got it. I also tried to catch std::runtime_error, but it did nothing.

4
General / Font Loading. [SOLVED]
« on: May 31, 2024, 01:43:25 am »
Hi,

I'm fairly new to SFML, so I might be missing something.
I've gone through a lot of information but nothing has helped.

After I load a font, the program just closes without any message.

I use SFML as a git submodule and build everything with CMake.

CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)

project(Ironforge)

set(CMAKE_CXX_STANDARD 20)

set(BUILD_SHARED_LIBS FALSE)

add_subdirectory(dep/SFML)

add_executable(${PROJECT_NAME}
        src/main.cpp
        src/Application.cpp
        src/State/StateManager.cpp
        src/UI/Button.cpp
        src/UI/MenuTabBar.cpp
        src/WindowManager.cpp
)

target_include_directories(${PROJECT_NAME}
        PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${CMAKE_CURRENT_SOURCE_DIR}/dep/SFML/include)

set(DEBUG_LIBS
        sfml-graphics-d)

set(RELEASE_LIBS
        sfml-graphics
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(${PROJECT_NAME} PRIVATE ${DEBUG_LIBS})
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
    target_link_libraries(${PROJECT_NAME} PRIVATE ${RELEASE_LIBS})
endif ()
 

After building the project and checking all dependencies and libraries through VS project settings ALL is correct. see screenshots.

I load the font in a class, which is in separate files

.h

#ifndef APPLICATION_H
#define APPLICATION_H

#include "macro.h"
#include "WindowManager.h"

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/String.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/VideoMode.hpp>

#include "SFML/Graphics/Font.hpp"

class Application
{
public:
    Application() = delete;
    explicit Application(sf::VideoMode videoMode);
    ~Application();

    DISABLE_COPY_ASSIGN(Application);

    void run();

private:
    void handleEvent();
    void update(sf::Time dt);
    void render();

    sf::Font* font;

    sf::RenderWindow window;
};

#endif // APPLICATION_H
 

.cpp relative only
Application::Application(sf::VideoMode videoMode)
    : window(videoMode, APP_TITLE, sf::Style::None, sf::State::Fullscreen)
{
    WindowManager::getInstance().setWindow(&window);
    *font = sf::Font::loadFromFile("resources/fonts/Cthulhumbus.ttf").value();
}
 

The paths to the fonts are also specified correctly, because if you specify incorrectly in the console displays an error about it.

It's also worth pointing out that apart from fonts, everything loads fine, textures, etc.

Hope someone can help ;)

Pages: [1]
anything