I have a render app. And it's the basis source code
std::vector<Eigen::Vector3f> frame_buffer;
I have rendered in the opencv
pipeline.refresh();
pipeline.draw();
cv::Mat image(700, 700, CV_32FC3, pipeline.raster.frameBuffer().data());
image.convertTo(image, CV_8UC3, 1.0f);
cv::cvtColor(image, image, cv::COLOR_RGB2BGRA);
cv::imshow("image", image);
It's correct.
But I wanna show in ImGUI. I use these code to convert and show in ImGUI.
// UI.h
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <opencv2/opencv.hpp>
// show function
while (!glfwWindowShouldClose(windows)){
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// window
ImGui::Begin("LRenderer");
pipeline.refresh();
pipeline.draw();
cv::Mat image(700, 700, CV_32FC3, pipeline.raster.frameBuffer().data());
image.convertTo(image, CV_8UC3, 1.0f);
cv::cvtColor(image, image, cv::COLOR_RGB2BGRA);
Mat2Texture(image, image_texture);
ImGui::Image((void*)(intptr_t)image_texture,
ImVec2(image.cols, image.rows));
ImGui::End();
// render
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(windows, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
const ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(windows);
}
// convert function
void LRenderer::UI::Mat2Texture(const cv::Mat& image, GLuint& imageTexture) {
if (image.empty()) {
std::cout << "image is empty! " << std::endl;
return;
} else {
// generate texture using GL commands
glGenTextures(1, &image_texture);
glBindTexture(GL_TEXTURE_2D, imageTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, image.cols, image.rows, 0, GL_RGBA,
GL_UNSIGNED_BYTE, image.data);
}
}
The glfw version is 3.3, and the glew version is 4.6. All up to date. I had try to use glad which version is 3.3 and 4.6, but it didn't work.
How should I do? Which library version is correct? And how to convert cv::mat
to ImTextureID
in ImGUI? I had seek for the solution before.
Which library version is correct? And how to convert cv::mat
to ImTextureID
in ImGUI?