Commit 80bc3149a3baf09808fdd0351fc182b8ca21a4e9
1 parent
557632d0
Fixed the rendering problem. A cube is not fully visible and rotates on screen, …
…added support for mouse movement in order to facilitate rotation
Showing
2 changed files
with
54 additions
and
63 deletions
Show diff stats
TextureTest.cu
1 | 1 | #include <math.h> |
2 | 2 | #include <iostream> |
3 | 3 | #include <vector> |
4 | -#include <GL/glew.h> | |
4 | +//#include <GL/glew.h> | |
5 | 5 | #include <GL/glut.h> |
6 | -#include <GL/glext.h> | |
6 | +//#include <GL/glext.h> | |
7 | 7 | #include "stim/gl/gl_texture.h" |
8 | 8 | #include "stim/gl/error.h" |
9 | 9 | GLuint texID; |
... | ... | @@ -17,8 +17,15 @@ |
17 | 17 | GLfloat vertex[8][3] = |
18 | 18 | {{0.0, 0.0, 1.0}, {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, |
19 | 19 | {0.0, 1.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 0.0, 0.0}, |
20 | - {1.0, 1.0, 0.0}, {1.0, 1.0, 1.0}}; | |
21 | - unsigned long tick = 0; | |
20 | + {1.0, 1.0, 0.0}, {1.0, 1.0, 1.0}}; | |
21 | +/* GLfloat vertex[8][3] = | |
22 | + {{-1.0, -1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, | |
23 | + {-1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, | |
24 | + {1.0, 1.0, -1.0}, {1.0, 1.0, 1.0}}; */ | |
25 | + unsigned long tick = 0; | |
26 | + static bool button1 = FALSE; | |
27 | + //static GLfloat viewDistance = 9.0; | |
28 | + //static float pos = 1.0; | |
22 | 29 | |
23 | 30 | void |
24 | 31 | glInit(int w, int h) |
... | ... | @@ -27,60 +34,19 @@ glInit(int w, int h) |
27 | 34 | glEnable(GL_TEXTURE_3D); |
28 | 35 | glEnable(GL_DEPTH_TEST); |
29 | 36 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
30 | - glClearColor(0.0, 1.0, 1.0, 1.0); | |
37 | + glClearColor(0.0, 0.0, 0.0, 0.0); | |
31 | 38 | glColor4d(0.0, 0.0, 0.0, 1.0); |
32 | - glPointSize(3.0); | |
39 | + //glPointSize(3.0); | |
33 | 40 | glShadeModel(GL_FLAT); |
34 | 41 | |
35 | - glViewport(0, 0, (GLsizei) 720, (GLsizei) 720); | |
42 | + glViewport(0, 0, (GLsizei) 1024, (GLsizei) 1024); | |
36 | 43 | glMatrixMode(GL_PROJECTION); |
37 | 44 | glLoadIdentity(); |
45 | + gluPerspective(180, 16.0/9.0, 5.0, 100.0); | |
46 | + glMatrixMode(GL_MODELVIEW); | |
47 | + | |
38 | 48 | CHECK_OPENGL_ERROR |
39 | 49 | } |
40 | - | |
41 | -/* | |
42 | -void | |
43 | -createTexture(stim::vec<unsigned long, 4> dims, unsigned char* data) | |
44 | -{ | |
45 | - glEnable(GL_TEXTURE_3D); | |
46 | - glGenTextures(1, &texID); | |
47 | - CHECK_OPENGL_ERROR | |
48 | - glBindTexture(GL_TEXTURE_3D, texID); | |
49 | - CHECK_OPENGL_ERROR | |
50 | - glTexParameteri(GL_TEXTURE_3D, | |
51 | - GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
52 | - glTexParameteri(GL_TEXTURE_3D, | |
53 | - GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
54 | - glTexParameteri(GL_TEXTURE_3D, | |
55 | - GL_TEXTURE_WRAP_S, GL_REPEAT); | |
56 | - | |
57 | - CHECK_OPENGL_ERROR | |
58 | - glTexParameteri(GL_TEXTURE_3D, | |
59 | - GL_TEXTURE_WRAP_S, GL_REPEAT); | |
60 | - glTexParameteri(GL_TEXTURE_3D, | |
61 | - GL_TEXTURE_WRAP_T, GL_REPEAT); | |
62 | - glTexParameteri(GL_TEXTURE_3D, | |
63 | - GL_TEXTURE_WRAP_R, GL_REPEAT); | |
64 | - CHECK_OPENGL_ERROR | |
65 | - | |
66 | - std::cerr << "test statement_before" << std::endl; | |
67 | - glTexImage3D(GL_TEXTURE_3D, | |
68 | - 0, | |
69 | - GL_RGB16, | |
70 | - // 1, | |
71 | - dims[1], | |
72 | - dims[2], | |
73 | - dims[3], | |
74 | - 0, | |
75 | - // GL_LUMINANCE, | |
76 | - GL_RGB, | |
77 | - GL_UNSIGNED_BYTE, | |
78 | - data); | |
79 | - std::cerr << "test statement" << std::endl; | |
80 | - //GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents | |
81 | - CHECK_OPENGL_ERROR | |
82 | -} | |
83 | -*/ | |
84 | 50 | void |
85 | 51 | renderScene() |
86 | 52 | { |
... | ... | @@ -88,10 +54,13 @@ renderScene() |
88 | 54 | glBindTexture(GL_TEXTURE_3D, texID); |
89 | 55 | CHECK_OPENGL_ERROR |
90 | 56 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
57 | + glMatrixMode(GL_PROJECTION); | |
91 | 58 | glLoadIdentity(); |
92 | - glTranslated(0.0, 0.0, 0.0); | |
93 | - glRotated(-90, 1.0, 0.0, 0.0); | |
94 | - glRotated((double)tick/100.0, 0.0, 0.0, 1.0); | |
59 | + glTranslatef(-0.4, -0.4, 0.4); | |
60 | + //gluLookAt(0,0, -viewDistance, 0, 0, -1, 0, 1, 0); | |
61 | + //gluLookAt(0,0, 0, 0, 0, 0, 0, 0, 0); | |
62 | + glRotatef(-90, 1.0, 0.0, 0.0); | |
63 | + glRotatef((float)tick/100.0, 1.0, 1.0, 1.0); | |
95 | 64 | CHECK_OPENGL_ERROR |
96 | 65 | //glVertex3f(0.0, 0.0, 0.0); |
97 | 66 | //glVertex3f(0.0, 1.0, 0.0); |
... | ... | @@ -148,6 +117,24 @@ renderScene() |
148 | 117 | //glutPostRedisplay(); |
149 | 118 | } |
150 | 119 | |
120 | +void MouseButton(int button, int state, int x, int y) | |
121 | +{ | |
122 | + if (button == GLUT_LEFT_BUTTON) | |
123 | + { | |
124 | + button1 = (state == GLUT_DOWN) ? TRUE : FALSE; | |
125 | + //tick = y; | |
126 | + } | |
127 | +} | |
128 | + | |
129 | +void MouseMotion(int x, int y) | |
130 | +{ | |
131 | + if(button1) | |
132 | + { | |
133 | + tick = y*10.0; | |
134 | + // pos = x*10.0; | |
135 | + glutPostRedisplay(); | |
136 | + } | |
137 | +} | |
151 | 138 | |
152 | 139 | void |
153 | 140 | idleFunction() |
... | ... | @@ -168,17 +155,18 @@ processKeys(unsigned char key, int x, int y) |
168 | 155 | void |
169 | 156 | changeSize(int w, int h) |
170 | 157 | { |
171 | - if (h==0) | |
172 | - h=1; | |
173 | - float ratio = w*1.0/h; | |
158 | + //if (h==0) | |
159 | + // h=1; | |
160 | + //float ratio = w*1.0/h; | |
174 | 161 | CHECK_OPENGL_ERROR |
162 | + glViewport(0,0,w,h); | |
175 | 163 | glMatrixMode(GL_PROJECTION); |
176 | 164 | |
177 | 165 | glLoadIdentity(); |
178 | 166 | |
179 | - glViewport(0,0,w,h); | |
180 | 167 | |
181 | - gluPerspective(45.0, 1, 0.1, 10.0); | |
168 | + //gluPerspective(90.0, 4.0/3.0, 0.1, 10.0); | |
169 | + gluPerspective(90, 4.0/3.0, 0.1, 100.0); | |
182 | 170 | |
183 | 171 | glMatrixMode(GL_MODELVIEW); |
184 | 172 | CHECK_OPENGL_ERROR |
... | ... | @@ -194,7 +182,7 @@ main(int argc, char **argv) |
194 | 182 | CHECK_OPENGL_ERROR |
195 | 183 | glutInit(&argc, argv); |
196 | 184 | glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); |
197 | - glutInitWindowSize(720, 720); | |
185 | + glutInitWindowSize(1024, 1024); | |
198 | 186 | glutCreateWindow("gl_texture"); |
199 | 187 | std::cout << " Initialization is complete in Glut" << std::endl; |
200 | 188 | |
... | ... | @@ -205,6 +193,9 @@ main(int argc, char **argv) |
205 | 193 | CHECK_OPENGL_ERROR |
206 | 194 | glutDisplayFunc(renderScene); |
207 | 195 | CHECK_OPENGL_ERROR |
196 | + glutMouseFunc(MouseButton); | |
197 | + | |
198 | + glutMotionFunc(MouseMotion); | |
208 | 199 | glPixelStorei(GL_UNPACK_ALIGNMENT,1); |
209 | 200 | glPixelStorei(GL_PACK_ALIGNMENT,1); |
210 | 201 | std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl; |
... | ... | @@ -212,14 +203,14 @@ main(int argc, char **argv) |
212 | 203 | stim::gl_texture<unsigned char> stack ("/home/pavel/Documents/Test_Data/"); |
213 | 204 | stack.createTexture(); |
214 | 205 | texID = stack.getTexture(); |
215 | - stack.save_images("test\????.jpg"); | |
206 | + //stack.save_images("test\????.jpg"); | |
216 | 207 | //stim::vec<unsigned long, 4> dims = stack.getDims(); |
217 | 208 | //unsigned char* dat = stack.getData(); |
218 | 209 | //createTexture(dims, dat); |
219 | 210 | std::cout << ("I have started an instance of the class") << std::endl; |
220 | 211 | |
221 | 212 | |
222 | - glInit(5, 5); | |
213 | + glInit(6, 6); | |
223 | 214 | CHECK_OPENGL_ERROR |
224 | 215 | glutIdleFunc(idleFunction); |
225 | 216 | CHECK_OPENGL_ERROR | ... | ... |