0

So, I'm trying to get better at manually compiling and building a program in VS Code. Also I'm running Windows 11 22H2 if that helps. I'm using SFML and ImGui with the ImGui-SFML backend. After days of trying to get a program up and running, I managed to get an SFML window created with a green circle in it. I then integrated ImGui and ImGui-SFML compiled into an .exe but when I run the exe, I get a shit ton of errors saying about how the Pixel Format is Invalid. this is my main.cpp, its just the example code from the ImGui-SFML repo:

#include "src/imgui-include/imgui.h"
#include "src/imgui-include/imgui-SFML.h"

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(window, event);

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

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::ShowDemoWindow();

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}

This is the Makefile I have setup:

CXX = g++
CXXFLAGS = -g -Wextra -Wall
INCLUDE = -Isrc/include -Isrc/imgui-include 
LIB = -Lsrc/lib -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-system -lsfml-window -lopengl32

IMGUI_FILES = src/imgui-include/imgui.cpp src/imgui-include/imgui_draw.cpp src/imgui-include/imgui_widgets.cpp src/imgui-include/imgui_demo.cpp src/imgui-include/imgui_tables.cpp
IMGUI_SFML_FILES = src/imgui-include/imgui-SFML.cpp

all: compile link

compile:
    $(CXX) $(CXXFLAGS) -c $(IMGUI_FILES) $(IMGUI_SFML_FILES) main.cpp $(INCLUDE)

link:
    $(CXX) $(CXXFLAGS) $(IMGUI_FILES) $(IMGUI_SFML_FILES) main.o -o main $(LIB)


clean:
    del *.o *.exe

This is my settings.json:

{
    "cmake.configureOnOpen": true,
    "cmake.showOptionsMovedNotification": false,
    "explorer.confirmDelete": false,
    "git.enableSmartCommit": true,
    "makefile.makefilePath": "C:/Users/Peyton/source/repos/FortEditor/Makefile",
    "git.autofetch": true,
    "C_Cpp.default.compilerPath": "C:\\MinGW\\bin\\g++.exe",
    "C_Cpp.default.includePath": [
        "${workspaceFolder}/**",
        "${workspaceFolder}/src/**"
    ]
}

and this is my terminal output:

Failed to activate OpenGL context: The pixel format is invalid.
Failed to activate the window's context
Failed to activate OpenGL context: The pixel format is invalid. 
Failed to activate OpenGL context: The handle is invalid. 
Failed to activate OpenGL context: The handle is invalid.

I've alread tried to get everything linked and workinng, I have opengl32.dll in with the rest of the dll's.

This is my ImGui and ImGui-SFML folder inside of the src directory

This is the include directory for all the SFML .hpp files, also in the src directory

this is the all the DLL's and Object files for the program as well as the main.cpp and main.exe file which are all kept in the root directory.

What I was expecting was a window to be created with a green circle in it and for an ImGui Demo Window to be created. Like I said before, I had managed to get a working SFML window to appear with a green circle inside it using the example code from the Linux setup.

5
  • Where did you get SFML? Did you build it yourself? Commented Apr 18, 2024 at 12:26
  • No, I didn't think about that. I just added the inlcudes and libs. Maybe I should have done that. Commented Apr 18, 2024 at 12:37
  • Building it yourself is not necessarily better. So where did you get it? Commented Apr 18, 2024 at 12:42
  • I downloaded the GCC 13.1.0 MinGW (SEH) - 64-bit from the official website here: sfml-dev.org/download/sfml/2.6.1 Commented Apr 18, 2024 at 14:37
  • You will have to step through the ImGui-SFML code with a debugger to at least isolate the lines that raise these pixel format errors. Commented Apr 19, 2024 at 7:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.