4 #define WIN32_LEAN_AND_MEAN 1
12 #if defined(__APPLE__)
13 #include <OpenGL/gl.h>
14 #include <OpenGL/glu.h>
20 #include "opencv2/core.hpp"
21 #include "opencv2/core/opengl.hpp"
22 #include "opencv2/core/cuda.hpp"
23 #include "opencv2/highgui.hpp"
27 using namespace cv::cuda;
29 const int win_width = 800;
30 const int win_height = 640;
39 void draw(void* userdata);
41 void draw(void* userdata)
43 DrawData* data = static_cast<DrawData*>(userdata);
45 glRotated(0.6, 0, 1, 0);
47 ogl::render(data->arr, data->indices, ogl::TRIANGLES);
50 int main(int argc, char* argv[])
55 cout << "Usage: " << argv[0] << " image" << endl;
56 filename = "../data/lena.jpg";
61 Mat img = imread(filename);
64 cerr << "Can't open image " << filename << endl;
68 namedWindow("OpenGL", WINDOW_OPENGL);
69 resizeWindow("OpenGL", win_width, win_height);
71 Mat_<Vec2f> vertex(1, 4);
72 vertex << Vec2f(-1, 1), Vec2f(-1, -1), Vec2f(1, -1), Vec2f(1, 1);
74 Mat_<Vec2f> texCoords(1, 4);
75 texCoords << Vec2f(0, 0), Vec2f(0, 1), Vec2f(1, 1), Vec2f(1, 0);
77 Mat_<int> indices(1, 6);
78 indices << 0, 1, 2, 2, 3, 0;
82 data.arr.setVertexArray(vertex);
83 data.arr.setTexCoordArray(texCoords);
84 data.indices.copyFrom(indices);
85 data.tex.copyFrom(img);
87 glMatrixMode(GL_PROJECTION);
89 gluPerspective(45.0, (double)win_width / win_height, 0.1, 100.0);
91 glMatrixMode(GL_MODELVIEW);
93 gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
95 glEnable(GL_TEXTURE_2D);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
99 glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
101 glDisable(GL_CULL_FACE);
103 setOpenGlDrawCallback("OpenGL", draw, &data);
107 updateWindow("OpenGL");
108 int key = waitKey(40);
109 if ((key & 0xff) == 27)
113 setOpenGlDrawCallback("OpenGL", 0, 0);