root / rgbdslam / external / siftgpu / src / TestWin / TestWinGlut.cpp @ 9240aaa3
History | View | Annotate | Download (3.82 KB)
1 | 9240aaa3 | Alex | ////////////////////////////////////////////////////////////////////////////
|
---|---|---|---|
2 | // File: TestWinGlut.cpp
|
||
3 | // Author: Changchang Wu
|
||
4 | // Description : Implementation of TestWinGlut Class
|
||
5 | //
|
||
6 | //
|
||
7 | //
|
||
8 | // Copyright (c) 2007 University of North Carolina at Chapel Hill
|
||
9 | // All Rights Reserved
|
||
10 | //
|
||
11 | // Permission to use, copy, modify and distribute this software and its
|
||
12 | // documentation for educational, research and non-profit purposes, without
|
||
13 | // fee, and without a written agreement is hereby granted, provided that the
|
||
14 | // above copyright notice and the following paragraph appear in all copies.
|
||
15 | //
|
||
16 | // The University of North Carolina at Chapel Hill make no representations
|
||
17 | // about the suitability of this software for any purpose. It is provided
|
||
18 | // 'as is' without express or implied warranty.
|
||
19 | //
|
||
20 | // Please send BUG REPORTS to ccwu@cs.unc.edu
|
||
21 | //
|
||
22 | ////////////////////////////////////////////////////////////////////////////
|
||
23 | |||
24 | #include <stdlib.h> |
||
25 | #ifdef __APPLE__
|
||
26 | #include "GLUT/glut.h" |
||
27 | #else
|
||
28 | #include "GL/glut.h" |
||
29 | #endif
|
||
30 | #include "BasicTestWin.h" |
||
31 | #include "TestWinGlut.h" |
||
32 | |||
33 | ///main etry
|
||
34 | |||
35 | int main(int argc, char**argv) |
||
36 | { |
||
37 | //
|
||
38 | ////uncomment this if you want to parse glut parameters
|
||
39 | glutInit(&argc, argv); |
||
40 | |||
41 | |||
42 | //create the glut window
|
||
43 | TestWinGlut twg(argc, argv); |
||
44 | // TestWinGlut twg2(0, NULL);
|
||
45 | |||
46 | |||
47 | //run the glut main loop to display all the TestWinGlut Windows
|
||
48 | TestWinGlut::Run(); |
||
49 | |||
50 | return 0; |
||
51 | } |
||
52 | |||
53 | //////////////////////////////////////////////////////////////////////
|
||
54 | // TestWinGlut Class
|
||
55 | //////////////////////////////////////////////////////////////////////
|
||
56 | |||
57 | |||
58 | |||
59 | /////////////////////////////////////////////////////////////////////
|
||
60 | ///Global Variables
|
||
61 | //////////////////////////////////////////////////////////////////////
|
||
62 | TestWinGlut* TestWinGlut::_win[TestWinGlut::MAX_TEST_WIN_GLUT]; |
||
63 | |||
64 | //////////////////////////////////////////////////////////////////////
|
||
65 | // Construction/Destruction
|
||
66 | //////////////////////////////////////////////////////////////////////
|
||
67 | |||
68 | |||
69 | |||
70 | TestWinGlut::TestWinGlut(int argc, char**argv) |
||
71 | |||
72 | { |
||
73 | //enable console output
|
||
74 | SetVerbose(); |
||
75 | ParseSiftParam(argc, argv); |
||
76 | |||
77 | //create glut window
|
||
78 | CreateGLUT(); |
||
79 | |||
80 | //parse parameters and run sift
|
||
81 | RunSiftGPU(); |
||
82 | |||
83 | |||
84 | } |
||
85 | |||
86 | TestWinGlut::~TestWinGlut() |
||
87 | { |
||
88 | |||
89 | } |
||
90 | |||
91 | |||
92 | |||
93 | void TestWinGlut::CreateGLUT()
|
||
94 | { |
||
95 | int id;
|
||
96 | glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE); |
||
97 | glutInitWindowSize (600,450); |
||
98 | if(_win_x != -1) glutInitWindowPosition(_win_x, _win_y); |
||
99 | id = glutCreateWindow ("SIFT_GPU");
|
||
100 | if(id>0) |
||
101 | { |
||
102 | if(id >=MAX_TEST_WIN_GLUT) exit(0);//should not happen... |
||
103 | |||
104 | //
|
||
105 | glutDisplayFunc (display); |
||
106 | glutKeyboardFunc(keyboard); |
||
107 | glutReshapeFunc (reshape); |
||
108 | glutIdleFunc(idle); |
||
109 | glutMotionFunc(motion); |
||
110 | glutMouseFunc(button); |
||
111 | //save a pointer to the stucture
|
||
112 | _win[id] = this;
|
||
113 | } |
||
114 | |||
115 | } |
||
116 | |||
117 | void TestWinGlut::idle()
|
||
118 | { |
||
119 | int id = glutGetWindow();
|
||
120 | _win[id]->OnIdle(); |
||
121 | } |
||
122 | |||
123 | void TestWinGlut::keyboard(unsigned char key, int x, int y) |
||
124 | { |
||
125 | int id = glutGetWindow();
|
||
126 | |||
127 | _win[id]->KeyInput(key); |
||
128 | glutPostRedisplay(); |
||
129 | } |
||
130 | void TestWinGlut::reshape(int w, int h) |
||
131 | { |
||
132 | int id = glutGetWindow();
|
||
133 | _win[id]->ReShape(w, h); |
||
134 | glutPostRedisplay(); |
||
135 | } |
||
136 | void TestWinGlut::display()
|
||
137 | { |
||
138 | static int firstcall=1; |
||
139 | int id = glutGetWindow();
|
||
140 | _win[id]->Display(); |
||
141 | glutSwapBuffers(); |
||
142 | if(firstcall ==0) |
||
143 | { |
||
144 | }else
|
||
145 | { |
||
146 | //if it is the first display call, redraw
|
||
147 | firstcall = 0;
|
||
148 | glutPostRedisplay(); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | void TestWinGlut::Run()
|
||
153 | { |
||
154 | glutMainLoop(); |
||
155 | } |
||
156 | |||
157 | void TestWinGlut::motion(int x, int y) |
||
158 | { |
||
159 | int id = glutGetWindow();
|
||
160 | _win[id]->MoveMouse(x, y); |
||
161 | } |
||
162 | |||
163 | void TestWinGlut::SetWindowTitle(char *title) |
||
164 | { |
||
165 | glutSetWindowTitle(title); |
||
166 | } |
||
167 | |||
168 | void TestWinGlut::button(int button, int state,int x, int y) |
||
169 | { |
||
170 | int id = glutGetWindow();
|
||
171 | if (button == GLUT_LEFT_BUTTON)
|
||
172 | { |
||
173 | if(state == GLUT_DOWN)
|
||
174 | _win[id]->StartMotion(x, y); |
||
175 | else if (state == GLUT_UP) |
||
176 | _win[id]->EndMotion(); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | void TestWinGlut::UpdateDisplay()
|
||
181 | { |
||
182 | glutPostRedisplay(); |
||
183 | } |
||
184 | |||
185 | void TestWinGlut::SetDisplaySize(int w, int h) |
||
186 | { |
||
187 | glutReshapeWindow(w, h); |
||
188 | } |