SFML community forums

Help => Window => Topic started by: KubixOFF on February 27, 2025, 10:30:53 am

Title: Integrating SFML with wxWidgets
Post by: KubixOFF on February 27, 2025, 10:30:53 am
Hello.
I trying to integrate SFML with wxWidgets control like in the tutorial on SFML website bu its not working. The Window i freez and cannot clik on close icon. Mabe this tutorial is old? I using sfml 3.0 and wxwidgets 3.2.6.
Can someone help me or show simple code how to draw sfml square into wxwidget control or something?
Title: Re: Integrating SFML with wxWidgets
Post by: eXpl0it3r on February 27, 2025, 10:43:06 am
You mean the tutorial for SFML 1.6, which is two major version ago and something over 15 years old? I do believe the tutorial is old indeed. ;D

What code have you written so far, maybe there's something that stands out.
Title: Re: Integrating SFML with wxWidgets
Post by: KubixOFF on February 27, 2025, 01:47:18 pm
Yes i talking about tutorial from 1.6 version.

this is my sample code i just want to my window show.


#include <wx/wxprec.h>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <wx/wx.h>

class TestFrame : public wxFrame {
public:
    TestFrame(const wxString& title);
    ~TestFrame();

};


class sfmlframe : public wxControl, public sf::RenderWindow
{
public:
    sfmlframe(wxWindow* Parent = NULL, wxWindowID id = -1, wxPoint point = wxDefaultPosition, wxSize size = wxDefaultSize, long s = 0) : wxControl(Parent, id, point, size, s)
    {
       
        sf::WindowHandle h = this->GetHandle();
        sf::RenderWindow::create(h);

    };
    ~sfmlframe() {};
};

TestFrame::TestFrame(const wxString& title)
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)) {



    sfmlframe* frame = new sfmlframe(this, wxID_ANY, wxDefaultPosition, wxSize(200, 150),0);

}

TestFrame::~TestFrame() {

}

class MyApp : public wxApp {
public:
    virtual bool OnInit();
};

bool MyApp::OnInit() {
    TestFrame* frame = new TestFrame(wxT("Sample code"));
    frame->Show(true);
    return true;
}

wxIMPLEMENT_APP(MyApp);



thats happend after compile - nothing will show
after i comment the line:
//  sfmlframe* frame = new sfmlframe(this, wxID_ANY, wxDefaultPosition, wxSize(200, 150),0);

and compile it the wxFrame will show
Title: Re: Integrating SFML with wxWidgets
Post by: eXpl0it3r on February 27, 2025, 02:48:00 pm
I don't see you implementing OnPaint.

Not sure if wxWidgets needs a specific call to process events, which is what I assume that is failing currently where you can't close the window.
Title: Re: Integrating SFML with wxWidgets
Post by: KubixOFF on March 04, 2025, 08:03:08 am
There is some problem with SFML 3.0.
When i use wxWidgets 3.2.6 and SFML 3.0 - on main private computer everything work perfect.
When i use the same stack and the same code in work computer there is issues and window is freez.

Then i download SFML 2.6.2 and with wxWidgets 3.2.6. work perfect. I think there is something wrong with new event api but mabe i doing something wrong.
Here is my code which work with wxWidgets 3.2.6 and sfml 3.0 on my private computer:
https://github.com/KubixOFFs/wxSFMLControl
Title: Re: Integrating SFML with wxWidgets
Post by: Hapax on March 10, 2025, 06:23:28 pm
Is this placing SFML inside wxWidgets? If so, is this issue only in Debug builds? How is it in Release builds?