Commit dd8ca6b96de0df308e206fc31a6b1638fd574cd9

Authored by Pavel Govyadinov
1 parent 25bb855e

recovered the majority of the code lost during the merge, code is functional, co…

…mpiles and runs with no error. There is still an error with the cuda aspect causing squashed impropper images
Showing 3 changed files with 247 additions and 41 deletions   Show diff stats
CMakeLists.txt
... ... @@ -56,6 +56,7 @@ cuda_add_executable(Texture_Test
56 56 ${SRC_H}
57 57 ${SRC_CPP}
58 58 ${SRC_CU})
  59 +cuda_add_cublas_to_target(Texture_Test)
59 60  
60 61 #set the link libraries
61 62 target_link_libraries(Texture_Test
... ...
TextureTest.cu
... ... @@ -2,9 +2,10 @@
2 2 #include <iostream>
3 3 #include <vector>
4 4 #include "stim/math/vector.h"
5   -//#include <GL/glew.h>
6   -#include <GL/glut.h>
7 5 //#include <GL/gl.h>
  6 +#include <GL/glew.h>
  7 +#include <GL/glut.h>
  8 +//#include <GL/freeglut.h>
8 9 //#include <GL/glext.h>
9 10 #include "stim/gl/gl_spider.h"
10 11 #include "stim/gl/gl_texture.h"
... ... @@ -15,6 +16,11 @@
15 16 stim::camera cam;
16 17 stim::camera Parker;
17 18 GLuint texID;
  19 + GLuint texID2;
  20 +// GLuint fboId;
  21 + stim::vec<float> D;
  22 +// GLuint rboId;
  23 +// GLuint pbo;
18 24 float a = -1.0;
19 25 float b = 1.0;
20 26 GLsizei size[2] = {900,900};
... ... @@ -24,10 +30,11 @@
24 30 GLint faces[6][4] =
25 31 {{0, 1, 2, 3}, {4, 5, 7, 6}, {1, 5, 7, 2},
26 32 {3, 2, 7, 6}, {0, 4, 6, 3}, {0, 1, 5, 4}};
27   - GLfloat vertexTex[8][3] =
  33 + GLfloat vertex[8][3] =
28 34 {{0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0},
29 35 {0.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
30 36 {0.0, 1.0, 0.0}, {1.0, 1.0, 0.0}};
  37 +
31 38 GLint lines[24] = {0,1,1,2,2,3,0,3,4,5,5,7,7,6,6,4,3,6,2,7,1,5,0,4};
32 39 GLfloat vertexDrw[8][3] =
33 40 {{a, a, b}, {b, a, b}, {b, b, b},
... ... @@ -39,8 +46,8 @@
39 46 stim::vec<float> p;
40 47 stim::vec<float> up;
41 48 stim::vec<float> d;
42   - static bool button1 = FALSE;
43   - static bool button_shift = FALSE;
  49 + static bool button1 = false;
  50 + static bool button_shift = false;
44 51 static float degtorad = 360/(2*M_PI);
45 52 static GLfloat adjustTex = 1.0/426.0;
46 53 static GLfloat adjustDrw = 2.0/426.0;
... ... @@ -57,6 +64,25 @@
57 64 stim::vec<float>p3;
58 65 stim::vec<float>p4;
59 66 //init for a cube
  67 +/*void
  68 +GenerateFBO(unsigned int width, unsigned int height)
  69 +{
  70 + glGenFramebuffers(1, &fboId);
  71 + glBindFramebuffer(GL_FRAMEBUFFER, fboId);
  72 + int numChannels = 3;
  73 + unsigned char* texels = new unsigned char[width * height * numChannels];
  74 + glGenTextures(1, &texID2);
  75 + glBindTexture(GL_TEXTURE_2D, texID2);
  76 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  77 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  78 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  79 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  80 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
  81 + width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texels);
  82 + delete[] texels;
  83 + glBindFramebuffer(GL_FRAMEBUFFER, 0);
  84 +}*/
  85 +
60 86 void
61 87 glInit()
62 88 {
... ... @@ -78,9 +104,22 @@ glInit()
78 104 glLoadIdentity();
79 105 glOrtho(-5.0, 2.0,-5.0, 2.0, -0.0, 1000.0);
80 106 glMatrixMode(GL_MODELVIEW);
81   - spidey = stim::gl_spider<float>(0.5, 0.5, 0.5, -0.1, -0.1, -0.1, 0.1, 0.1);
  107 + spidey = stim::gl_spider<float>(0.515372, 0.564174, 0.494553,
  108 + 0.130563, -0.98295, -0.129467,
  109 + 0.5, 0.5);
  110 + spidey.attachSpider(texID);
82 111 Parker.setPosition(spidey.getPosition());
83 112 Parker.LookAt(spidey.getDirection());
  113 +// GenerateFBO(400, 200);
  114 + spidey.initCuda();
  115 + //glGenRenderbuffers(1, &rboId);
  116 + //glBindRenderbuffer(GL_RENDERBUFFER, rboId);
  117 + //GLuint rboId;
  118 + //glGenRenderbuffers(1, &rboId);
  119 + //glBindRenderbuffer(GL_RENDERBUFFER, rboId);
  120 + //glGenBuffers(1, &pbo);
  121 + //glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
  122 + //glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, 426*426*sizeof(uchar4), NULL, GL_DYNAMIC_DRAW_ARB);
84 123 CHECK_OPENGL_ERROR
85 124 }
86 125  
... ... @@ -104,11 +143,13 @@ DrawCube()
104 143 void
105 144 DrawPlanes()
106 145 {
  146 + glEnable(GL_TEXTURE_3D);
  147 + glBindTexture(GL_TEXTURE_3D, texID);
107 148 p1 = spidey.ver.p(1,1);
108 149 p2 = spidey.ver.p(1,0);
109 150 p3 = spidey.ver.p(0,0);
110 151 p4 = spidey.ver.p(0,1);
111   - glPushName(VERTICAL);
  152 + //glPushName(VERTICAL);
112 153 glBegin(GL_QUADS);
113 154 glTexCoord3f(
114 155 p1[0],
... ... @@ -151,12 +192,12 @@ DrawPlanes()
151 192 p4[2]
152 193 );
153 194 glEnd();
154   - glPopName();
  195 + //glPopName();
155 196 p1 = spidey.hor.p(1,1);
156 197 p2 = spidey.hor.p(1,0);
157 198 p3 = spidey.hor.p(0,0);
158 199 p4 = spidey.hor.p(0,1);
159   - glPushName(HORIZONTAL);
  200 + //glPushName(HORIZONTAL);
160 201 glBegin(GL_QUADS);
161 202 glTexCoord3f(
162 203 p1[0],
... ... @@ -199,11 +240,15 @@ DrawPlanes()
199 240 p4[2]
200 241 );
201 242 glEnd();
202   - glPopName();
  243 + //glPopName();
  244 + glBindTexture(GL_TEXTURE_3D, 0);
  245 + glDisable(GL_TEXTURE_3D);
203 246 }
204 247 void
205 248 DrawSpiders()
206 249 {
  250 + glEnable(GL_TEXTURE_3D);
  251 + glBindTexture(GL_TEXTURE_3D, texID);
207 252 p1 = spidey.hor.p(1,1);
208 253 p2 = spidey.hor.p(1,0);
209 254 p3 = spidey.hor.p(0,0);
... ... @@ -214,25 +259,25 @@ DrawSpiders()
214 259 p1[1],
215 260 p1[2]
216 261 );
217   - glVertex2f( -5.0,-5.0);
  262 + glVertex2f(0.0,0.0);
218 263 glTexCoord3f(
219 264 p2[0],
220 265 p2[1],
221 266 p2[2]
222 267 );
223   - glVertex2f(-3.0, -5.0);
  268 + glVertex2f(1.0, 0.0);
224 269 glTexCoord3f(
225 270 p3[0],
226 271 p3[1],
227 272 p3[2]
228 273 );
229   - glVertex2f(-3.0, -3.0);
  274 + glVertex2f(1.0, 2.0);
230 275 glTexCoord3f(
231 276 p4[0],
232 277 p4[1],
233 278 p4[2]
234 279 );
235   - glVertex2f(-5.0, -3.0);
  280 + glVertex2f(0.0, 2.0);
236 281 glEnd();
237 282 p1 = spidey.ver.p(1,1);
238 283 p2 = spidey.ver.p(1,0);
... ... @@ -245,31 +290,32 @@ DrawSpiders()
245 290 p1[1],
246 291 p1[2]
247 292 );
248   - glVertex2f(-5.0, -2.9);
  293 + glVertex2f(1.0, 0.0);
249 294 glTexCoord3f(
250 295 p2[0],
251 296 p2[1],
252 297 p2[2]
253 298 );
254   - glVertex2f(-3.0, -2.9);
  299 + glVertex2f(2.0, 0.0);
255 300 glTexCoord3f(
256 301 p3[0],
257 302 p3[1],
258 303 p3[2]
259 304 );
260   - glVertex2f(-3.0, -0.9);
  305 + glVertex2f(2.0, 2.0);
261 306 glTexCoord3f(
262 307 p4[0],
263 308 p4[1],
264 309 p4[2]
265 310 );
266   - glVertex2f(-5.0, -0.9);
  311 + glVertex2f(1.0, 2.0);
267 312 glEnd();
  313 + glBindTexture(GL_TEXTURE_3D, 0);
  314 + glDisable(GL_TEXTURE_3D);
268 315 }
269 316  
270   -
271   -
272 317 //render cube
  318 +
273 319 void
274 320 renderScene()
275 321 {
... ... @@ -278,10 +324,8 @@ renderScene()
278 324 glLoadIdentity();
279 325 glOrtho(-5.0, 2.0,-5.0, 2.0, -0.0, 1000.0);
280 326 glMatrixMode(GL_MODELVIEW);
281   -
282 327 glInitNames();
283   - glEnable(GL_TEXTURE_3D);
284   - glBindTexture(GL_TEXTURE_3D, texID);
  328 + glClearColor(0,0,0,0);
285 329 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
286 330 glMatrixMode(GL_MODELVIEW);
287 331 glLoadIdentity();
... ... @@ -290,16 +334,83 @@ renderScene()
290 334 d = cam.getLookAt();
291 335 gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], up[0], up[1], up[2]);
292 336 DrawPlanes();
293   - glDisable(GL_TEXTURE_3D);
294 337 DrawCube();
295   - glEnable(GL_TEXTURE_3D);
296   - glBindTexture(GL_TEXTURE_3D, texID);
297   - glViewport(0,0, 800,800);
298   - gluOrtho2D(-5.0, 2.0,-5.0, 2.0);
  338 + //glEnable(GL_TEXTURE_2D);
  339 +
  340 +
  341 + //glBindTexture(GL_TEXTURE_2D, texID);
  342 + /*glBindFramebuffer(GL_FRAMEBUFFER, fboId);
  343 + glFramebufferTexture2D(
  344 + GL_FRAMEBUFFER,
  345 + GL_COLOR_ATTACHMENT0,
  346 + GL_TEXTURE_2D,
  347 + texID2,
  348 + 0
  349 + );
  350 + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texID2, 0);
  351 + glBindFramebuffer(GL_FRAMEBUFFER, fboId);
  352 + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
  353 + glDrawBuffers(1, DrawBuffers);
  354 + if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  355 + std::cout << "damn" << std::endl;
  356 + glBindTexture(GL_TEXTURE_2D, texID2);
  357 + glClearColor(1,1,1,1);
  358 + glClear(GL_COLOR_BUFFER_BIT);
  359 + //glLoadIdentity();
  360 + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  361 + CHECK_OPENGL_ERROR
  362 + glMatrixMode(GL_PROJECTION);
  363 + glLoadIdentity();
  364 + glMatrixMode(GL_MODELVIEW);
299 365 glLoadIdentity();
  366 + glViewport(0,0,400,200);
  367 + gluOrtho2D(0.0, 2.0, 0.0, 2.0);
300 368 DrawSpiders();
301   - glDisable(GL_TEXTURE_3D);
302   -
  369 + //glPopMatrix();
  370 + //DrawSpiders2();
  371 + //glFlush();
  372 + //glFinish();
  373 + CHECK_OPENGL_ERROR
  374 + glBindFramebuffer(GL_FRAMEBUFFER, 0);
  375 + glBindTexture(GL_TEXTURE_2D, 0);*/
  376 + glBindFramebuffer(GL_READ_FRAMEBUFFER, spidey.getFB());
  377 + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
  378 + glBlitFramebuffer(0,0,400,200, 0, 0, 400, 200, GL_COLOR_BUFFER_BIT, GL_NEAREST);
  379 + CHECK_OPENGL_ERROR
  380 + //glBindFramebuffer(GL_FRAMEBUFFER,0);
  381 + //glBindTexture(GL_TEXTURE_3D, texID);
  382 + //glGenerateMipmap(GL_TEXTURE_3D);
  383 + //glBindTexture(GL_TEXTURE_3D, 0);
  384 + //glViewport(0,0, 800,800);
  385 +
  386 + //GLint curbuf;
  387 + //glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &curbuf);
  388 + //std::cout << curbuf << std::endl;
  389 +
  390 + //glViewport(0,0,600,600);
  391 + //glBindFramebuffer(GL_FRAMEBUFFER, fboId);
  392 +
  393 + //glDrawBuffer(GL_FRAMEBUFFER0);
  394 + //glDrawBuffer(fboId);
  395 + //glClearColor(1,1,1,1);
  396 + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  397 + //glLoadIdentity();
  398 + //std::cout << fboId << std::endl;
  399 + //DrawSpiders();
  400 +
  401 + //glBlitFramebuffer(0.0,0.0,1,1,0.0,0.0,1,1, GL_COLOR_BUFFER_BIT, GL_LINEAR);
  402 + //gluOrtho2D(-5.0, -3.0, -5.0, -1.0);
  403 + //glClearColor(1,1,1,1);
  404 + //glBindTexture(GL_TEXTURE_3D, texID);
  405 + //glPushMatrix();
  406 + //glGenerateMipmap(GL_TEXTURE_3D);
  407 + //glBindTexture(GL_TEXTURE_3D, 0);
  408 + //glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &curbuf);
  409 + //std::cout << curbuf << std::endl;
  410 +
  411 +// glCopyImageSubData(fboId, GL_FRAMEBUFFER, 0, 0, 0, 0, GL_FRONT_AND_BACK, GL_NONE, 0, 0, 0, 0, 20, 20, 0);
  412 +
  413 +
303 414 glutSwapBuffers();
304 415 }
305 416  
... ... @@ -310,15 +421,16 @@ MouseButton(int button, int state, int x, int y)
310 421  
311 422 if (button == GLUT_LEFT_BUTTON)
312 423 {
313   - button1 = (state == GLUT_DOWN) ? TRUE : FALSE;
  424 + button1 = (state == GLUT_DOWN) ? true : false;
314 425 button_shift = glutGetModifiers();
315 426 prevmousePos[0] = (float)x;
316 427 prevmousePos[1] = (float)y;
317 428 }
318   - if (button == GLUT_RIGHT_BUTTON)
  429 + if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
319 430 {
320 431 std::cout << spidey.getPosition() << std::endl
321 432 << spidey.getDirection() << std::endl;
  433 + std::cout << spidey.getCost() << std::endl;
322 434 }
323 435 }
324 436  
... ... @@ -354,6 +466,13 @@ idleFunction()
354 466 }
355 467  
356 468 void
  469 +printCost()
  470 +{
  471 +
  472 +}
  473 +
  474 +
  475 +void
357 476 processSpecialKeys(int key, int xx, int yy)
358 477 {
359 478 switch(key) {
... ... @@ -466,7 +585,21 @@ processKeys(unsigned char key, int x, int y)
466 585 {
467 586 spidey.Step();
468 587 std::cout << "Took a step" << std::endl;
469   - }
  588 + }
  589 + if (key == 43)
  590 + {
  591 + stim::vec<float> temp = spidey.getMagnitude();
  592 + temp = temp + 0.001;
  593 + spidey.setMagnitude(temp);
  594 + spidey.Update();
  595 + }
  596 + if (key == 45)
  597 + {
  598 + stim::vec<float> temp = spidey.getMagnitude();
  599 + temp = temp - 0.001;
  600 + spidey.setMagnitude(temp);
  601 + spidey.Update();
  602 + }
470 603 }
471 604  
472 605  
... ... @@ -488,11 +621,6 @@ main(int argc, char **argv)
488 621 CHECK_OPENGL_ERROR
489 622 glutInit(&argc, argv);
490 623 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
491   - int overlaySupport = glutLayerGet(GLUT_OVERLAY_POSSIBLE);
492   - if(overlaySupport) {
493   - std::cout << "Overlay YAY!" << std::endl;
494   - } else {
495   - std::cout << "Overlay AW!" << std::endl;}
496 624 glutInitWindowSize(size[0], size[1]);
497 625 glutCreateWindow("gl_texture");
498 626 //std::cout << " Initialization is complete in Glut" << std::endl;
... ... @@ -511,8 +639,15 @@ main(int argc, char **argv)
511 639 glutMotionFunc(MouseMotion);
512 640  
513 641 //std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl;
514   -
  642 + GLenum err = glewInit();
  643 + if (GLEW_OK != err)
  644 + {
  645 + std::cerr << "Failed" << std::endl;
  646 + fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
  647 + }
515 648 stim::gl_texture<unsigned char> stack ("/home/pavel/Documents/Test_Data/");
  649 + //stack.setDimensions(1.0,1.0,1.0);
  650 + //D = stack.getDimensions();
516 651 stack.createTexture();
517 652 texID = stack.getTexture();
518 653 //std::cout << ("I have started an instance of the class") << std::endl;
... ... @@ -528,7 +663,6 @@ main(int argc, char **argv)
528 663 }
529 664  
530 665  
531   -
532 666 //old code
533 667  
534 668 /*
... ... @@ -746,3 +880,74 @@ DrawPlanes()
746 880 glPopName();
747 881 }
748 882 */
  883 +/*
  884 +void
  885 +renderScene()
  886 + {
  887 + glEnable(GL_TEXTURE_3D);
  888 + glBindTexture(GL_TEXTURE_3D, texID);
  889 + CHECK_OPENGL_ERROR
  890 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  891 + glMatrixMode(GL_PROJECTION);
  892 + //glMatrixMode(GL_MODELVIEW);
  893 + glLoadIdentity();
  894 + glTranslatef(-0.4, -0.4, 0.4);
  895 + //gluLookAt(0,0, -viewDistance, 0, 0, -1, 0, 1, 0);
  896 + //gluLookAt(0,0, 0, 0, 0, 0, 0, 0, 0);
  897 + glRotatef(-90, 1.0, 0.0, 0.0);
  898 + glRotatef((float)tick/100.0, 1.0, 1.0, 1.0);
  899 + CHECK_OPENGL_ERROR
  900 + //glVertex3f(0.0, 0.0, 0.0);
  901 + //glVertex3f(0.0, 1.0, 0.0);
  902 + //glVertex3f(1.0, 1.0, 0.0);
  903 + //glVertex3f(1.0, 0.0, 0.0);
  904 + glBegin(GL_QUADS);
  905 + for (int i = 0; i < 6; i++) {
  906 + //first vertex
  907 +// std::cout << "setting vertex 1 of face " << i
  908 + << " vertex located at " <<
  909 + "[" << vertex[faces[i][0]][0] << ","
  910 + << vertex[faces[i][0]][1] << ","
  911 + << vertex[faces[i][0]][2] << "]" << std::endl;//
  912 + glTexCoord3f(vertex[faces[i][0]][0],
  913 + vertex[faces[i][0]][1],
  914 + vertex[faces[i][0]][2]);
  915 +
  916 + glVertex3f(vertex[faces[i][0]][0],
  917 + vertex[faces[i][0]][1],
  918 + vertex[faces[i][0]][2]);
  919 +
  920 + //second vertex
  921 + glTexCoord3f(vertex[faces[i][1]][0],
  922 + vertex[faces[i][1]][1],
  923 + vertex[faces[i][1]][2]);
  924 +
  925 + glVertex3f(vertex[faces[i][1]][0],
  926 + vertex[faces[i][1]][1],
  927 + vertex[faces[i][1]][2]);
  928 +
  929 + //third vertex
  930 + glTexCoord3f(vertex[faces[i][2]][0],
  931 + vertex[faces[i][2]][1],
  932 + vertex[faces[i][2]][2]);
  933 +
  934 + glVertex3f(vertex[faces[i][2]][0],
  935 + vertex[faces[i][2]][1],
  936 + vertex[faces[i][2]][2]);
  937 +
  938 + //fourth vertex
  939 + glTexCoord3f(vertex[faces[i][3]][0],
  940 + vertex[faces[i][3]][1],
  941 + vertex[faces[i][3]][2]);
  942 +
  943 + glVertex3f(vertex[faces[i][3]][0],
  944 + vertex[faces[i][3]][1],
  945 + vertex[faces[i][3]][2]);
  946 + }
  947 + glEnd();
  948 +
  949 + CHECK_OPENGL_ERROR
  950 + glutSwapBuffers();
  951 + //glutPostRedisplay();
  952 + }
  953 +*/
... ...
1   -Subproject commit a39577bf6661bcb962a7329abbebc66e501b1dac
  1 +Subproject commit f1e9fe98ca570f1b64ea27b8ee1efe4f9428d355
... ...