From dd8ca6b96de0df308e206fc31a6b1638fd574cd9 Mon Sep 17 00:00:00 2001 From: Pavel Govyadinov Date: Fri, 22 May 2015 19:04:36 -0500 Subject: [PATCH] recovered the majority of the code lost during the merge, code is functional, compiles and runs with no error. There is still an error with the cuda aspect causing squashed impropper images --- CMakeLists.txt | 1 + TextureTest.cu | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- stim | 2 +- 3 files changed, 247 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3016c08..825ecf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ cuda_add_executable(Texture_Test ${SRC_H} ${SRC_CPP} ${SRC_CU}) +cuda_add_cublas_to_target(Texture_Test) #set the link libraries target_link_libraries(Texture_Test diff --git a/TextureTest.cu b/TextureTest.cu index 85036ab..2b344ba 100644 --- a/TextureTest.cu +++ b/TextureTest.cu @@ -2,9 +2,10 @@ #include #include #include "stim/math/vector.h" -//#include -#include //#include +#include +#include +//#include //#include #include "stim/gl/gl_spider.h" #include "stim/gl/gl_texture.h" @@ -15,6 +16,11 @@ stim::camera cam; stim::camera Parker; GLuint texID; + GLuint texID2; +// GLuint fboId; + stim::vec D; +// GLuint rboId; +// GLuint pbo; float a = -1.0; float b = 1.0; GLsizei size[2] = {900,900}; @@ -24,10 +30,11 @@ GLint faces[6][4] = {{0, 1, 2, 3}, {4, 5, 7, 6}, {1, 5, 7, 2}, {3, 2, 7, 6}, {0, 4, 6, 3}, {0, 1, 5, 4}}; - GLfloat vertexTex[8][3] = + GLfloat vertex[8][3] = {{0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 1.0, 0.0}}; + 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}; GLfloat vertexDrw[8][3] = {{a, a, b}, {b, a, b}, {b, b, b}, @@ -39,8 +46,8 @@ stim::vec p; stim::vec up; stim::vec d; - static bool button1 = FALSE; - static bool button_shift = FALSE; + static bool button1 = false; + static bool button_shift = false; static float degtorad = 360/(2*M_PI); static GLfloat adjustTex = 1.0/426.0; static GLfloat adjustDrw = 2.0/426.0; @@ -57,6 +64,25 @@ stim::vecp3; stim::vecp4; //init for a cube +/*void +GenerateFBO(unsigned int width, unsigned int height) +{ + glGenFramebuffers(1, &fboId); + glBindFramebuffer(GL_FRAMEBUFFER, fboId); + int numChannels = 3; + unsigned char* texels = new unsigned char[width * height * numChannels]; + glGenTextures(1, &texID2); + glBindTexture(GL_TEXTURE_2D, texID2); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, + width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texels); + delete[] texels; + glBindFramebuffer(GL_FRAMEBUFFER, 0); +}*/ + void glInit() { @@ -78,9 +104,22 @@ glInit() glLoadIdentity(); glOrtho(-5.0, 2.0,-5.0, 2.0, -0.0, 1000.0); glMatrixMode(GL_MODELVIEW); - spidey = stim::gl_spider(0.5, 0.5, 0.5, -0.1, -0.1, -0.1, 0.1, 0.1); + spidey = stim::gl_spider(0.515372, 0.564174, 0.494553, + 0.130563, -0.98295, -0.129467, + 0.5, 0.5); + spidey.attachSpider(texID); Parker.setPosition(spidey.getPosition()); Parker.LookAt(spidey.getDirection()); +// GenerateFBO(400, 200); + spidey.initCuda(); + //glGenRenderbuffers(1, &rboId); + //glBindRenderbuffer(GL_RENDERBUFFER, rboId); + //GLuint rboId; + //glGenRenderbuffers(1, &rboId); + //glBindRenderbuffer(GL_RENDERBUFFER, rboId); + //glGenBuffers(1, &pbo); + //glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); + //glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, 426*426*sizeof(uchar4), NULL, GL_DYNAMIC_DRAW_ARB); CHECK_OPENGL_ERROR } @@ -104,11 +143,13 @@ DrawCube() void DrawPlanes() { + glEnable(GL_TEXTURE_3D); + glBindTexture(GL_TEXTURE_3D, texID); p1 = spidey.ver.p(1,1); p2 = spidey.ver.p(1,0); p3 = spidey.ver.p(0,0); p4 = spidey.ver.p(0,1); - glPushName(VERTICAL); + //glPushName(VERTICAL); glBegin(GL_QUADS); glTexCoord3f( p1[0], @@ -151,12 +192,12 @@ DrawPlanes() p4[2] ); glEnd(); - glPopName(); + //glPopName(); p1 = spidey.hor.p(1,1); p2 = spidey.hor.p(1,0); p3 = spidey.hor.p(0,0); p4 = spidey.hor.p(0,1); - glPushName(HORIZONTAL); + //glPushName(HORIZONTAL); glBegin(GL_QUADS); glTexCoord3f( p1[0], @@ -199,11 +240,15 @@ DrawPlanes() p4[2] ); glEnd(); - glPopName(); + //glPopName(); + glBindTexture(GL_TEXTURE_3D, 0); + glDisable(GL_TEXTURE_3D); } void DrawSpiders() { + glEnable(GL_TEXTURE_3D); + glBindTexture(GL_TEXTURE_3D, texID); p1 = spidey.hor.p(1,1); p2 = spidey.hor.p(1,0); p3 = spidey.hor.p(0,0); @@ -214,25 +259,25 @@ DrawSpiders() p1[1], p1[2] ); - glVertex2f( -5.0,-5.0); + glVertex2f(0.0,0.0); glTexCoord3f( p2[0], p2[1], p2[2] ); - glVertex2f(-3.0, -5.0); + glVertex2f(1.0, 0.0); glTexCoord3f( p3[0], p3[1], p3[2] ); - glVertex2f(-3.0, -3.0); + glVertex2f(1.0, 2.0); glTexCoord3f( p4[0], p4[1], p4[2] ); - glVertex2f(-5.0, -3.0); + glVertex2f(0.0, 2.0); glEnd(); p1 = spidey.ver.p(1,1); p2 = spidey.ver.p(1,0); @@ -245,31 +290,32 @@ DrawSpiders() p1[1], p1[2] ); - glVertex2f(-5.0, -2.9); + glVertex2f(1.0, 0.0); glTexCoord3f( p2[0], p2[1], p2[2] ); - glVertex2f(-3.0, -2.9); + glVertex2f(2.0, 0.0); glTexCoord3f( p3[0], p3[1], p3[2] ); - glVertex2f(-3.0, -0.9); + glVertex2f(2.0, 2.0); glTexCoord3f( p4[0], p4[1], p4[2] ); - glVertex2f(-5.0, -0.9); + glVertex2f(1.0, 2.0); glEnd(); + glBindTexture(GL_TEXTURE_3D, 0); + glDisable(GL_TEXTURE_3D); } - - //render cube + void renderScene() { @@ -278,10 +324,8 @@ renderScene() glLoadIdentity(); glOrtho(-5.0, 2.0,-5.0, 2.0, -0.0, 1000.0); glMatrixMode(GL_MODELVIEW); - glInitNames(); - glEnable(GL_TEXTURE_3D); - glBindTexture(GL_TEXTURE_3D, texID); + glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -290,16 +334,83 @@ renderScene() d = cam.getLookAt(); gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], up[0], up[1], up[2]); DrawPlanes(); - glDisable(GL_TEXTURE_3D); DrawCube(); - glEnable(GL_TEXTURE_3D); - glBindTexture(GL_TEXTURE_3D, texID); - glViewport(0,0, 800,800); - gluOrtho2D(-5.0, 2.0,-5.0, 2.0); + //glEnable(GL_TEXTURE_2D); + + + //glBindTexture(GL_TEXTURE_2D, texID); + /*glBindFramebuffer(GL_FRAMEBUFFER, fboId); + glFramebufferTexture2D( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + texID2, + 0 + ); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texID2, 0); + glBindFramebuffer(GL_FRAMEBUFFER, fboId); + GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; + glDrawBuffers(1, DrawBuffers); + if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + std::cout << "damn" << std::endl; + glBindTexture(GL_TEXTURE_2D, texID2); + glClearColor(1,1,1,1); + glClear(GL_COLOR_BUFFER_BIT); + //glLoadIdentity(); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + CHECK_OPENGL_ERROR + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glViewport(0,0,400,200); + gluOrtho2D(0.0, 2.0, 0.0, 2.0); DrawSpiders(); - glDisable(GL_TEXTURE_3D); - + //glPopMatrix(); + //DrawSpiders2(); + //glFlush(); + //glFinish(); + CHECK_OPENGL_ERROR + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0);*/ + glBindFramebuffer(GL_READ_FRAMEBUFFER, spidey.getFB()); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBlitFramebuffer(0,0,400,200, 0, 0, 400, 200, GL_COLOR_BUFFER_BIT, GL_NEAREST); + CHECK_OPENGL_ERROR + //glBindFramebuffer(GL_FRAMEBUFFER,0); + //glBindTexture(GL_TEXTURE_3D, texID); + //glGenerateMipmap(GL_TEXTURE_3D); + //glBindTexture(GL_TEXTURE_3D, 0); + //glViewport(0,0, 800,800); + + //GLint curbuf; + //glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &curbuf); + //std::cout << curbuf << std::endl; + + //glViewport(0,0,600,600); + //glBindFramebuffer(GL_FRAMEBUFFER, fboId); + + //glDrawBuffer(GL_FRAMEBUFFER0); + //glDrawBuffer(fboId); + //glClearColor(1,1,1,1); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glLoadIdentity(); + //std::cout << fboId << std::endl; + //DrawSpiders(); + + //glBlitFramebuffer(0.0,0.0,1,1,0.0,0.0,1,1, GL_COLOR_BUFFER_BIT, GL_LINEAR); + //gluOrtho2D(-5.0, -3.0, -5.0, -1.0); + //glClearColor(1,1,1,1); + //glBindTexture(GL_TEXTURE_3D, texID); + //glPushMatrix(); + //glGenerateMipmap(GL_TEXTURE_3D); + //glBindTexture(GL_TEXTURE_3D, 0); + //glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &curbuf); + //std::cout << curbuf << std::endl; + +// glCopyImageSubData(fboId, GL_FRAMEBUFFER, 0, 0, 0, 0, GL_FRONT_AND_BACK, GL_NONE, 0, 0, 0, 0, 20, 20, 0); + + glutSwapBuffers(); } @@ -310,15 +421,16 @@ MouseButton(int button, int state, int x, int y) if (button == GLUT_LEFT_BUTTON) { - button1 = (state == GLUT_DOWN) ? TRUE : FALSE; + button1 = (state == GLUT_DOWN) ? true : false; button_shift = glutGetModifiers(); prevmousePos[0] = (float)x; prevmousePos[1] = (float)y; } - if (button == GLUT_RIGHT_BUTTON) + if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { std::cout << spidey.getPosition() << std::endl << spidey.getDirection() << std::endl; + std::cout << spidey.getCost() << std::endl; } } @@ -354,6 +466,13 @@ idleFunction() } void +printCost() +{ + +} + + +void processSpecialKeys(int key, int xx, int yy) { switch(key) { @@ -466,7 +585,21 @@ processKeys(unsigned char key, int x, int y) { spidey.Step(); std::cout << "Took a step" << std::endl; - } + } + if (key == 43) + { + stim::vec temp = spidey.getMagnitude(); + temp = temp + 0.001; + spidey.setMagnitude(temp); + spidey.Update(); + } + if (key == 45) + { + stim::vec temp = spidey.getMagnitude(); + temp = temp - 0.001; + spidey.setMagnitude(temp); + spidey.Update(); + } } @@ -488,11 +621,6 @@ main(int argc, char **argv) CHECK_OPENGL_ERROR glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); - int overlaySupport = glutLayerGet(GLUT_OVERLAY_POSSIBLE); - if(overlaySupport) { - std::cout << "Overlay YAY!" << std::endl; - } else { - std::cout << "Overlay AW!" << std::endl;} glutInitWindowSize(size[0], size[1]); glutCreateWindow("gl_texture"); //std::cout << " Initialization is complete in Glut" << std::endl; @@ -511,8 +639,15 @@ main(int argc, char **argv) glutMotionFunc(MouseMotion); //std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl; - + GLenum err = glewInit(); + if (GLEW_OK != err) + { + std::cerr << "Failed" << std::endl; + fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); + } stim::gl_texture stack ("/home/pavel/Documents/Test_Data/"); + //stack.setDimensions(1.0,1.0,1.0); + //D = stack.getDimensions(); stack.createTexture(); texID = stack.getTexture(); //std::cout << ("I have started an instance of the class") << std::endl; @@ -528,7 +663,6 @@ main(int argc, char **argv) } - //old code /* @@ -746,3 +880,74 @@ DrawPlanes() glPopName(); } */ +/* +void +renderScene() + { + glEnable(GL_TEXTURE_3D); + glBindTexture(GL_TEXTURE_3D, texID); + CHECK_OPENGL_ERROR + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + //glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(-0.4, -0.4, 0.4); + //gluLookAt(0,0, -viewDistance, 0, 0, -1, 0, 1, 0); + //gluLookAt(0,0, 0, 0, 0, 0, 0, 0, 0); + glRotatef(-90, 1.0, 0.0, 0.0); + glRotatef((float)tick/100.0, 1.0, 1.0, 1.0); + CHECK_OPENGL_ERROR + //glVertex3f(0.0, 0.0, 0.0); + //glVertex3f(0.0, 1.0, 0.0); + //glVertex3f(1.0, 1.0, 0.0); + //glVertex3f(1.0, 0.0, 0.0); + glBegin(GL_QUADS); + for (int i = 0; i < 6; i++) { + //first vertex +// std::cout << "setting vertex 1 of face " << i + << " vertex located at " << + "[" << vertex[faces[i][0]][0] << "," + << vertex[faces[i][0]][1] << "," + << vertex[faces[i][0]][2] << "]" << std::endl;// + glTexCoord3f(vertex[faces[i][0]][0], + vertex[faces[i][0]][1], + vertex[faces[i][0]][2]); + + glVertex3f(vertex[faces[i][0]][0], + vertex[faces[i][0]][1], + vertex[faces[i][0]][2]); + + //second vertex + glTexCoord3f(vertex[faces[i][1]][0], + vertex[faces[i][1]][1], + vertex[faces[i][1]][2]); + + glVertex3f(vertex[faces[i][1]][0], + vertex[faces[i][1]][1], + vertex[faces[i][1]][2]); + + //third vertex + glTexCoord3f(vertex[faces[i][2]][0], + vertex[faces[i][2]][1], + vertex[faces[i][2]][2]); + + glVertex3f(vertex[faces[i][2]][0], + vertex[faces[i][2]][1], + vertex[faces[i][2]][2]); + + //fourth vertex + glTexCoord3f(vertex[faces[i][3]][0], + vertex[faces[i][3]][1], + vertex[faces[i][3]][2]); + + glVertex3f(vertex[faces[i][3]][0], + vertex[faces[i][3]][1], + vertex[faces[i][3]][2]); + } + glEnd(); + + CHECK_OPENGL_ERROR + glutSwapBuffers(); + //glutPostRedisplay(); + } +*/ diff --git a/stim b/stim index a39577b..f1e9fe9 160000 --- a/stim +++ b/stim @@ -1 +1 @@ -Subproject commit a39577bf6661bcb962a7329abbebc66e501b1dac +Subproject commit f1e9fe98ca570f1b64ea27b8ee1efe4f9428d355 -- libgit2 0.21.4