4 #define WIN32_LEAN_AND_MEAN 1
10 #include <OpenGL/gl.h>
11 #include <OpenGL/glu.h>
17 #include "opencv2/core/core.hpp"
18 #include "opencv2/core/opengl_interop.hpp"
19 #include "opencv2/core/gpumat.hpp"
20 #include "opencv2/highgui/highgui.hpp"
24 using namespace cv::gpu;
26 const int win_width = 800;
27 const int win_height = 640;
36 void draw(void* userdata);
38 void draw(void* userdata)
40 DrawData* data = static_cast<DrawData*>(userdata);
42 glRotated(0.6, 0, 1, 0);
44 ogl::render(data->arr, data->indices, ogl::TRIANGLES);
47 int main(int argc, char* argv[])
51 cout << "Usage: " << argv[0] << " image" << endl;
55 Mat img = imread(argv[1]);
58 cerr << "Can't open image " << argv[1] << endl;
62 namedWindow("OpenGL", WINDOW_OPENGL);
63 resizeWindow("OpenGL", win_width, win_height);
65 Mat_<Vec2f> vertex(1, 4);
66 vertex << Vec2f(-1, 1), Vec2f(-1, -1), Vec2f(1, -1), Vec2f(1, 1);
68 Mat_<Vec2f> texCoords(1, 4);
69 texCoords << Vec2f(0, 0), Vec2f(0, 1), Vec2f(1, 1), Vec2f(1, 0);
71 Mat_<int> indices(1, 6);
72 indices << 0, 1, 2, 2, 3, 0;
76 data.arr.setVertexArray(vertex);
77 data.arr.setTexCoordArray(texCoords);
78 data.indices.copyFrom(indices);
79 data.tex.copyFrom(img);
81 glMatrixMode(GL_PROJECTION);
83 gluPerspective(45.0, (double)win_width / win_height, 0.1, 100.0);
85 glMatrixMode(GL_MODELVIEW);
87 gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
89 glEnable(GL_TEXTURE_2D);
92 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
93 glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
95 glDisable(GL_CULL_FACE);
97 setOpenGlDrawCallback("OpenGL", draw, &data);
101 updateWindow("OpenGL");
102 int key = waitKey(40);
103 if ((key & 0xff) == 27)
107 setOpenGlDrawCallback("OpenGL", 0, 0);