#include #include #include #include #include #include #ifdef __APPLE__ #include #include #include #else #include #include #endif using namespace cv; using namespace std; using namespace std::chrono; using time_stamp = time_point; 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(system_clock::now()); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutCreateWindow("opengl_opencv_example"); glutFullScreen(); glutDisplayFunc(displayMe); glutMainLoop(); return 0; }