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

Author Topic: [Solved] Strange compiler errors in imgui-SFML.cpp code  (Read 6469 times)

0 Members and 3 Guests are viewing this topic.

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
[Solved] Strange compiler errors in imgui-SFML.cpp code
« on: September 14, 2024, 12:23:07 pm »
Hi, I have this issue with Imgui-SFML library set up in Visual Studio. For some reason, when I try to build it, I get compiler errors in library code (imgui-SFML.cpp file):

Severity        Code    Description     Project File    Line    Suppression State       Details
Error   C2665   'ImGui::ImageButton': no overloaded function could convert all the argument types       SFMLGame        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp     1024   

Severity        Code    Description     Project File    Line    Suppression State       Details
Error   C2665   'ImGui::ImageButton': no overloaded function could convert all the argument types       SFMLGame        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp     1041

Severity        Code    Description     Project File    Line    Suppression State       Details
Error   C2665   'ImGui::ImageButton': no overloaded function could convert all the argument types       SFMLGame        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp     1075

I use Visual Studio 2022.

Versions:
SFML: 2.5.1
ImGui: 1.91.1
ImGui-SFML: 2.6
« Last Edit: September 18, 2024, 09:22:43 am by TRI99ER »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11038
    • View Profile
    • development blog
    • Email
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #1 on: September 14, 2024, 01:43:46 pm »
Cross-post from GitHub.

What's your application code?
Sounds to me you're trying to call ImGui::ImageButton with invalid parameters.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #2 on: September 14, 2024, 04:07:29 pm »
I don't call ImGui::ImageButton at all:

#include <iostream>
#include <memory>
#include <fstream>

#include <SFML/Graphics.hpp>
#include "imgui.h"
#include "imgui-SFML.h"

int main(int argc, char* argv[]) {
        const int wWidth = 1280;
        const int wHeight = 720;

        sf::RenderWindow window(sf::VideoMode(wWidth, wHeight), "SFML works!");
        window.setFramerateLimit(60);

        ImGui::SFML::Init(window);
        sf::Clock deltaClock;

        ImGui::GetStyle().ScaleAllSizes(1.0f);

        float c[3] = { 0.0f, 1.0f, 1.0f };

        float circleRadius = 50;
        int circleSegments = 32;
        float circleSpeedX = 1.0f;
        float circleSpeedY = 0.5f;
        bool drawCircle = true;
        bool drawText = true;

        sf::CircleShape circle(circleRadius, circleSegments);
        circle.setPosition(10.0f, 10.0f);

        sf::Font myFont;

        if (!myFont.loadFromFile("fonts/tech.ttf")) {
                std::cerr << "Could not load font!\n";
                exit(-1);
        }

        sf::Text text("Sample Text", myFont, 24);

        text.setPosition(0, wHeight - (float)text.getCharacterSize());

        char displayString[255] = "Sample Text";

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

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

                        if (event.type == sf::Event::KeyPressed) {
                                std::cout << "Key pressed with code = " << event.key.code << std::endl;

                                if (event.key.code == sf::Keyboard::X) {
                                        circleSpeedX *= -1.0f;
                                }
                        }

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

                        ImGui::Begin("Window title");
                        ImGui::Text("Window text!");
                        ImGui::Checkbox("Draw Circle", &drawCircle);
                        ImGui::SameLine();
                        ImGui::Checkbox("Draw Text", &drawText);
                        ImGui::SliderFloat("Radius", &circleRadius, 0.0f, 300.0f);
                        ImGui::SliderInt("Sides", &circleSegments, 3, 64);
                        ImGui::ColorEdit3("Color Circle", c);
                        ImGui::InputText("Text", displayString, 255);
                        if (ImGui::Button("Set Text")) {
                                text.setString(displayString);
                        }
                        ImGui::SameLine();
                        if (ImGui::Button("Reset Circle")) {
                                circle.setPosition(0, 0);
                        }
                        ImGui::End();

                        circle.setFillColor(sf::Color(c[0] * 255, c[1] * 255, c[2] * 255));
                        circle.setPointCount(circleSegments);
                        circle.setRadius(circleRadius);

                        circle.setPosition(circle.getPosition().x + circleSpeedX, circle.getPosition().y + circleSpeedY);

                        window.clear();
                        if (drawCircle) {
                                window.draw(circle);
                        }
                        if (drawText) {
                                window.draw(text);
                        }
                        ImGui::SFML::Render(window);
                        window.display();
                }
        }

        return 0;
}
 
« Last Edit: September 14, 2024, 04:09:52 pm by TRI99ER »

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #3 on: September 14, 2024, 04:29:39 pm »
I suspect, I did something wrong at setting it up, but I redid it a few times from start following the instructions and it still doesn't work.
« Last Edit: September 14, 2024, 05:56:34 pm by TRI99ER »

kojack

  • Sr. Member
  • ****
  • Posts: 344
  • C++/C# game dev teacher.
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #4 on: September 14, 2024, 11:57:51 pm »
It's most likely a version difference. ImGui-SFML acts as a wrapper around things like passing SFML graphics (sprites, rendertextures, etc) to ImGui. But you are using a 2018 version of SFML with a Feb 2024 version of ImGui-SFML and a Sep 2024 version of ImGui. Either ImGui-SFML's 2.6 is no longer compatible with SFML 2.5.1 from 6 years ago, or ImGui has changed something since ImGui-SFML came out.

I've had to fix these in the past, but I can't remember what the changes were. I've got 627 imgui-sfml.cpp files on my PC, so a bit hard to check. :) I think it was adding SFML 3 support before imgui-sfml did, I've been on 3 for quite a while now.

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #5 on: September 15, 2024, 08:37:12 am »
Then it shouldn't say "SFML >= 2.5.0" on the https://github.com/SFML/imgui-sfml/tree/2.6.x page.

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #6 on: September 15, 2024, 08:40:09 am »
I've updated to SFML 2.6.1 and it still produced the same errors.

kojack

  • Sr. Member
  • ****
  • Posts: 344
  • C++/C# game dev teacher.
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #7 on: September 15, 2024, 10:48:57 am »
Next step will be to show us the errors.
The error list version only says the type of error, not the details of what it's having trouble with.

Go to the compiler output and it should have a big block of text saying something like this:
Quote
1>F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,6): error C2665: 'BBB::stuff': no overloaded function could convert all the argument types
1>    F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(495,15):
1>    could be 'void BBB::stuff(float)'
1>        F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,6):
1>        'void BBB::stuff(float)': cannot convert argument 1 from 'const char [5]' to 'float'
1>            F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,12):
1>            There is no context in which this conversion is possible
1>    F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(494,15):
1>    or       'void BBB::stuff(int)'
1>        F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,6):
1>        'void BBB::stuff(int)': cannot convert argument 1 from 'const char [5]' to 'int'
1>            F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,12):
1>            There is no context in which this conversion is possible
1>    F:\work\kf\tests\kil_ui_test\kil_ui_test.cpp(508,6):
1>    while trying to match the argument list '(const char [5])'
In this case, it's showing I have an overloaded function that takes a float and another that takes an int. But I tried to call them using a literal string. It didn't think either function could convert a string to what they needed.

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #8 on: September 15, 2024, 12:32:20 pm »
Here's the relevant part:
Quote
1>imgui-SFML.cpp
1>C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1024,19): error C2665: 'ImGui::ImageButton': no overloaded function could convert all the argument types
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui.h(565,29):
1>    could be 'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)'
1>        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1024,19):
1>        'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)': cannot convert argument 1 from 'ImTextureID' to 'const char *'
1>            C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1024,31):
1>            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1024,19):
1>    while trying to match the argument list '(ImTextureID, ImVec2, ImVec2, ImVec2, const int, ImColor, ImColor)'
1>C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1041,19): error C2665: 'ImGui::ImageButton': no overloaded function could convert all the argument types
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui.h(565,29):
1>    could be 'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)'
1>        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1041,19):
1>        'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)': cannot convert argument 1 from 'ImTextureID' to 'const char *'
1>            C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1041,31):
1>            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1041,19):
1>    while trying to match the argument list '(ImTextureID, ImVec2, ImVec2, ImVec2, const int, ImColor, ImColor)'
1>C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1075,19): error C2665: 'ImGui::ImageButton': no overloaded function could convert all the argument types
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui.h(565,29):
1>    could be 'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)'
1>        C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1075,19):
1>        'bool ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)': cannot convert argument 1 from 'ImTextureID' to 'const char *'
1>            C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1075,31):
1>            Conversion from 'void*' to pointer to non-'void' requires an explicit cast
1>    C:\Users\tri99er\source\repos\SFMLGame\imgui\imgui-SFML.cpp(1075,19):
1>    while trying to match the argument list '(ImTextureID, ImVec2, ImVec2, ImVec2, const int, ImColor, ImColor)'

I appreciate you guiding me through this step by step.
« Last Edit: September 15, 2024, 12:33:59 pm by TRI99ER »

kojack

  • Sr. Member
  • ****
  • Posts: 344
  • C++/C# game dev teacher.
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #9 on: September 16, 2024, 11:00:55 am »
I think your imgui-sfml might be an older version.

In the error log it says it's trying to pass arguments like this (ImTextureID, ImVec2, ImVec2, ImVec2, const int, ImColor, ImColor) to a function that looks like ImGui::ImageButton(const char *,ImTextureID,const ImVec2 &,const ImVec2 &,const ImVec2 &,const ImVec4 &,const ImVec4 &)

There's two differences there: The ImGui::ImageButton has a const char* at the start and no int in the middle.
This was a breaking change in ImGui 1.89. Back in 1.88 and below, it did have version of ImageButton that would have worked.

ImGui-SFML adapted to the change in the 2.6 branch on 8 december 2023. So it looks like your ImGui-SFML is from before that date. Try updating ImGui-SFML's 2.6 branch to the latest (should be from feb 2024).

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #10 on: September 16, 2024, 01:12:14 pm »
Thank you, that solved it. I just took the last release version instead of the last commit to the branch. That former one is outdated by a few months.

Now I'm still getting one error, this time it's a linker one:
Quote
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>C:\Users\tri99er\source\repos\SFMLGame\x64\Debug\SFMLGame.exe : fatal error LNK1120: 1 unresolved externals

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11038
    • View Profile
    • development blog
    • Email
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #11 on: September 16, 2024, 01:40:04 pm »
If you link SFML statically, you need to define SFML_STATIC
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #12 on: September 16, 2024, 01:57:37 pm »
Defined already, not working.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11038
    • View Profile
    • development blog
    • Email
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #13 on: September 16, 2024, 03:44:37 pm »
Well are you linking SFML statically (the libraries with the -s suffix).
If not, then you should not define SFML_STATIC
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TRI99ER

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Strange compiler errors in imgui-SFML.cpp code
« Reply #14 on: September 17, 2024, 08:59:51 am »
I am linking them with -s suffix.