Thu, 10/24/2019 - 09:35
Forums:
Hi,
I want to use occt + glfw + imgui to program a app.
Here is how I init occt and render
void OCCTRenderer::initViewer(GLFWwindow* win)
{
if (m_Display.IsNull())
m_Display = new Aspect_DisplayConnection;
Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (m_Display, false);
Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver);
aViewer->SetDefaultLights();
aViewer->SetLightOn();
aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
aViewer->ActivateGrid (Aspect_GT_Rectangular, Aspect_GDM_Lines);
m_View = aViewer->CreateView();
m_ctx = new OpenGl_Context;
if (m_ctx->Init(glfwGetWin32Window(win), GetDC(glfwGetWin32Window(win)), glfwGetWGLContext(win))) {
Handle(OpenGl_FrameBuffer) fbo = new OpenGl_FrameBuffer;
if (fbo->Init(m_ctx, 800, 600, GL_RGBA8, GL_DEPTH24_STENCIL8)) {
m_View->View()->SetFBO(fbo);
m_Texture = fbo->ColorTexture();
}
}
m_View->SetImmediateUpdate (false);
m_View->ChangeRenderingParams().ToShowStats = true;
m_Context = new AIS_InteractiveContext (aViewer);
m_Context->SetDisplayMode(AIS_Shaded, true);
}
void OCCTRenderer::Render(void)
{
if (!m_View.IsNull()) {
m_ctx->MakeCurrent();
if (m_View->IsInvalidated()){
m_View->Redraw();
} else if (m_ToRedraw){
m_View->RedrawImmediate();
}
}
m_ToRedraw = false;
}
and render like this
while (!glfwWindowShouldClose(window))
{
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents();
renderer.Render();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
renderer.Draw();
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
void OCCTRenderer::Draw()
{
ImGui::SetNextWindowSize(ImVec2(800, 600));
ImGui::Begin(u8"OCCT Viewer");
ImGui::Image((ImTextureID)m_Texture->TextureId(), m_Size, ImVec2(0, 1), ImVec2(1, 0));
ImGui::End();
}
But all I got is a black image.
So, how to render occt into a texture ?
Thanks
Thu, 10/24/2019 - 19:13
Just make it to works.
we still need to pass the glfw window and opengl context to view, so it can init a opengl workspace.
Sat, 05/21/2022 - 12:06
Can you share your source code, please? Or maybe somebody can tell how to "pass the glfw window and opengl context to view"?
Sat, 05/21/2022 - 14:14
Daniil Ellovich wrote:
Have you tried glfw sample coming with OCCT itself?
Sun, 09/19/2021 - 01:11
Hi @trlsmax_152734, can you share your working solution?