提问人:zhisheng 提问时间:11/13/2023 最后编辑:zhisheng 更新时间:11/14/2023 访问量:52
如何使用 wxWidgets 和 OpenGL 实现循环渲染?[关闭]
How to use wxWidgets and OpenGL to implement loop rendering? [closed]
问:
我使用 wxwidgts 和 wxGLCanvas 创建一个应用程序,一般框架是工作线程循环渲染,主线程显示渲染结果。
主线程创建 wxGLCanvas 继承对象。
class OpenGLWidget : public wxGLCanvas
{
public:
explicit OpenGLWidget(wxWindow* parent, const wxGLAttributes &canvasAttrs);
~OpenGLWidget();
public:
void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event);
private:
bool initializeGL();
bool initializeOpenGLFunctions();
private:
wxGLContext *openGLContext;
private:
bool m_bGLInitialized;
};
OpenGLWidget::OpenGLWidget(wxWindow* parent, const wxGLAttributes &canvasAttrs)
: wxGLCanvas(parent, canvasAttrs),
m_bGLInitialized(false),
{
wxGLContextAttrs ctxAttrs;
ctxAttrs.PlatformDefaults().CoreProfile().OGLVersion(3, 3).EndList();
openGLContext = new wxGLContext(this, nullptr, &ctxAttrs);
if(!openGLContext->IsOK())
{
LOGE("This sample needs an OpenGL 3.3 capable driver.");
delete openGLContext;
openGLContext = nullptr;
}
Bind(wxEVT_PAINT, &OpenGLWidget::OnPaint, this);
Bind(wxEVT_SIZE, &OpenGLWidget::OnSize, this);
}
我想创建一个工作线程来执行实际的渲染工作,然后在主线程中显示渲染结果。 在 initializeGL() 中:
m_pRender = new Render(this, openGLContext);
if(m_pRender->Create() != wxTHREAD_NO_ERROR)
{
LOGE("Create RenderThread failed");
}
m_pRender->Run();
class Render : public wxThread
{
public:
Render(OpenGLWidget* widget, wxGLContext* mainContext);
~Render();
public:
virtual void *Entry();
OpenGLWidget* m_pGLWidget;
wxGLContext* m_pMainContext;
};
Render::Render(OpenGLWidget* widget, wxGLContext* mainContext)
: m_pGLWidget(widget),
m_pMainContext(mainContext)
{
}
void* Render::Entry()
{
m_pMainContext->SetCurrent(*m_pGLWidget);
while(true)
{
//Rendering code
//notify update
}
return nullptr;
}
这就是主要代码,在运行程序时,大多数都存在以下问题。然后程序崩溃了。
[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
IPP: ../../src/xcb_io.c:641: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.
[1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-2cl534qm.gfu" 1>"/tmp/Microsoft-MIEngine-Out-eb4ux03a.icf"
我试图将XInitThreads添加到OnInit()函数中,但它没有用。 有什么问题,请问。
答: 暂无答案
评论