74 lines
1.8 KiB
C++
74 lines
1.8 KiB
C++
#include <opencv2/core.hpp>
|
|
#include <opencv2/core/opengl.hpp>
|
|
#include <opencv2/imgcodecs.hpp>
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
#include <opencv2/highgui.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#ifdef __APPLE__
|
|
#include <OpenGL/gl.h>
|
|
#include <OpenGL/gl3.h>
|
|
#include <GLUT/glut.h>
|
|
#else
|
|
#include <GL/glew.h>
|
|
#include <GL/glut.h>
|
|
#endif
|
|
|
|
using namespace cv;
|
|
using namespace std;
|
|
using namespace std::chrono;
|
|
using time_stamp = time_point<system_clock, microseconds>;
|
|
|
|
Mat image;
|
|
GLuint imageTexture;
|
|
GLint screenWidth = 0;
|
|
GLint screenHeight = 0;
|
|
time_stamp ts;
|
|
|
|
void getScreenDimensions () {
|
|
if (screenWidth == 0 && screenHeight == 0) {
|
|
GLint dims[4] = {0};
|
|
glGetIntegerv(GL_VIEWPORT, dims);
|
|
screenWidth = dims[2];
|
|
screenHeight = dims[3];
|
|
cout << screenWidth << "," << screenHeight << endl;
|
|
}
|
|
}
|
|
|
|
void displayMe(void)
|
|
{
|
|
getScreenDimensions();
|
|
|
|
string image_path = samples::findFile("chart.png");
|
|
Mat image = imread(image_path, IMREAD_COLOR);
|
|
#if (CV_VERSION_MAJOR >= 4)
|
|
cvtColor(image, image, cv::COLOR_BGR2RGB);
|
|
#else
|
|
cvtColor(image, image, CV_BGR2RGB);
|
|
#endif
|
|
|
|
// Set every pixel in the frame buffer to the current clear color.
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
glBegin(GL_POLYGON);
|
|
glColor3f(1, 0, 0); glVertex3f(-1.0, -1.0, 0.5);
|
|
glColor3f(0, 1, 0); glVertex3f(1.0, -1.0, 0);
|
|
glColor3f(0, 0, 1); glVertex3f(1.0, 1.0, 0);
|
|
glColor3f(0, 0, 0); glVertex3f(-1.0, 1.0, 0);
|
|
glEnd();
|
|
|
|
// Flush drawing command buffer to make drawing happen as soon as possible.
|
|
glFlush();
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
ts = time_point_cast<microseconds>(system_clock::now());
|
|
glutInit(&argc, argv);
|
|
glutInitDisplayMode(GLUT_SINGLE);
|
|
glutCreateWindow("opengl_opencv_example");
|
|
glutFullScreen();
|
|
glutDisplayFunc(displayMe);
|
|
glutMainLoop();
|
|
return 0;
|
|
} |