can render 2 cv::mats

This commit is contained in:
Kueffner, Maximilian
2025-03-14 19:32:40 +01:00
parent 5ecc38a9ca
commit 0b541348b0
15 changed files with 290 additions and 12 deletions
+15
View File
@@ -0,0 +1,15 @@
set(RENDERSRC)
set(RENDERLIBNAME pixelariumrenderlib)
set(RENDERLIBSRC
CvMatRender.cpp)
add_library(${RENDERLIBNAME} STATIC
${RENDERLIBSRC})
target_link_libraries(${RENDERLIBNAME}
PRIVATE pixelariumimagelib)
target_include_directories(${RENDERLIBNAME}
PRIVATE ${CMAKE_SOURCE_DIR}/lib)
+49
View File
@@ -0,0 +1,49 @@
#include "CvMatRender.hpp"
#include <cstdint>
using namespace pixelarium::imaging;
pixelarium::render::CvMatRender::CvMatRender(const Image& img)
{
this->_img = img.GetImage();
this->_texture = 0;
cv::cvtColor(this->_img, this->_img, cv::COLOR_BGR2RGBA);
}
/*static*/ void pixelarium::render::matToTexture(const cv::Mat& image, GLuint* texture)
{
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// auto image = img.GetImage();
switch (image.type())
{
case CV_16U:
case CV_16UC3:
case 26:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_UNSIGNED_SHORT, image.data);
break;
case 5:
case 29:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_FLOAT, image.data);
break;
default:
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.cols, image.rows, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image.data);
break;
}
}
GLuint pixelarium::render::CvMatRender::Render()
{
matToTexture(this->_img, &this->_texture);
return this->_texture;
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#ifdef _WIN32
#include <windows.h>
#include <GL/GL.h>
#else
#define GL_SILENCE_DEPRECATION
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
#endif
#include "imaging/Image.hpp"
namespace pixelarium::render
{
static void matToTexture(const cv::Mat& image,
GLuint* texture);
class CvMatRender
{
public:
explicit CvMatRender(const pixelarium::imaging::Image& img);
// void* Render();
GLuint Render();
private:
cv::Mat _img;
GLuint _texture;
};
} // namespace pixelarium::render