4 #define WIN32_LEAN_AND_MEAN 1
10 #include <OpenGL/gl.h>
11 #include <OpenGL/glu.h>
17 #include "opencv2/core.hpp"
18 #include "opencv2/core/opengl.hpp"
19 #include "opencv2/core/cuda.hpp"
20 #include "opencv2/highgui.hpp"
24 using namespace cv::cuda;
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[])
52 cout << "Usage: " << argv[0] << " image" << endl;
53 filename = "../data/lena.jpg";
58 Mat img = imread(filename);
61 cerr << "Can't open image " << filename << endl;
65 namedWindow("OpenGL", WINDOW_OPENGL);
66 resizeWindow("OpenGL", win_width, win_height);
68 Mat_<Vec2f> vertex(1, 4);
69 vertex << Vec2f(-1, 1), Vec2f(-1, -1), Vec2f(1, -1), Vec2f(1, 1);
71 Mat_<Vec2f> texCoords(1, 4);
72 texCoords << Vec2f(0, 0), Vec2f(0, 1), Vec2f(1, 1), Vec2f(1, 0);
74 Mat_<int> indices(1, 6);
75 indices << 0, 1, 2, 2, 3, 0;
79 data.arr.setVertexArray(vertex);
80 data.arr.setTexCoordArray(texCoords);
81 data.indices.copyFrom(indices);
82 data.tex.copyFrom(img);
84 glMatrixMode(GL_PROJECTION);
86 gluPerspective(45.0, (double)win_width / win_height, 0.1, 100.0);
88 glMatrixMode(GL_MODELVIEW);
90 gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
92 glEnable(GL_TEXTURE_2D);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
96 glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
98 glDisable(GL_CULL_FACE);
100 setOpenGlDrawCallback("OpenGL", draw, &data);
104 updateWindow("OpenGL");
105 char key = (char)waitKey(40);
110 setOpenGlDrawCallback("OpenGL", 0, 0);