1 |
|
2 |
|
3 |
|
4 | #include "stdafx.h"
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | #include "cv.h"
|
10 | #include "highgui.h"
|
11 |
|
12 | #include <GL/glut.h>
|
13 |
|
14 |
|
15 | void init(void)
|
16 | {
|
17 | glClearColor (0.0, 0.0, 0.0, 0.0);
|
18 | glShadeModel (GL_FLAT);
|
19 | glEnable(GL_CULL_FACE);
|
20 | }
|
21 |
|
22 | void display(void)
|
23 | {
|
24 | glClear (GL_COLOR_BUFFER_BIT);
|
25 | glColor3f (1.0, 1.0, 1.0);
|
26 | glLoadIdentity ();
|
27 |
|
28 |
|
29 | glTranslated(0, 0, -25);
|
30 |
|
31 |
|
32 | glBegin(GL_QUADS);
|
33 | glVertex3f(-10.0f, 10.0f, 0.0f);
|
34 | glVertex3f(-10.0f,-10.0f, 0.0f);
|
35 | glVertex3f( 10.0f,-10.0f, 0.0f);
|
36 | glVertex3f( 10.0f, 10.0f, 0.0f);
|
37 | glEnd();
|
38 |
|
39 | glFlush ();
|
40 | }
|
41 |
|
42 | void reshape (int w, int h)
|
43 | {
|
44 | glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
45 |
|
46 | glMatrixMode (GL_PROJECTION);
|
47 | glLoadIdentity ();
|
48 | gluPerspective(90, (double)w/h, 5.0, 400.0);
|
49 |
|
50 | glMatrixMode (GL_MODELVIEW);
|
51 | gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -400.0, 0.0, 1.0, 0.0);
|
52 | }
|
53 |
|
54 | void keyboard(unsigned char key, int x, int y)
|
55 | {
|
56 | switch (key) {
|
57 | case 27:
|
58 | exit(0);
|
59 | break;
|
60 | }
|
61 | }
|
62 |
|
63 | int main(int argc, char** argv)
|
64 | {
|
65 | int screenWidth = 512, screenHeight = 512;
|
66 |
|
67 | glutInit(&argc, argv);
|
68 | glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
|
69 | glutInitWindowSize (screenWidth, screenHeight);
|
70 | glutInitWindowPosition (100, 100);
|
71 | glutCreateWindow (argv[0]);
|
72 | init ();
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | reshape (screenWidth, screenHeight);
|
80 |
|
81 | int error_code = glGetError();
|
82 | glDrawBuffer(GL_FRONT);
|
83 | display();
|
84 |
|
85 | cv::Mat image1;
|
86 | image1.create(screenHeight,screenWidth, CV_8UC3);
|
87 | glReadPixels(0, 0, screenWidth, screenHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, (uchar*)image1.data);
|
88 | int error_code1 = glGetError();
|
89 |
|
90 | const char *title = "glReadPixels";
|
91 | cv::namedWindow(title);
|
92 | int error_code2 = glGetError();
|
93 |
|
94 | cv::imshow(title, image1);
|
95 | int error_code3 = glGetError();
|
96 | cv::waitKey(2000);
|
97 | int error_code4 = glGetError();
|
98 | cv::destroyWindow(title);
|
99 | int error_code5 = glGetError();
|
100 | image1.release();
|
101 |
|
102 | int error_code6 = glGetError();
|
103 |
|
104 | glDrawBuffer(GL_FRONT);
|
105 | int error_code7 = glGetError();
|
106 |
|
107 |
|
108 | display();
|
109 |
|
110 | cv::Mat image2;
|
111 | image2.create(screenHeight,screenWidth, CV_8UC3);
|
112 | glReadPixels(0, 0, screenWidth, screenHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, (uchar*)image2.data);
|
113 | int error_code8 = glGetError();
|
114 |
|
115 | cv::imshow(title, image2);
|
116 | cv::waitKey(5000);
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | return 0;
|
122 | } |