Commit 50b46cfe793159cf1db0589e2ca520984ceb3272
1 parent
c5de4e1a
CMakeLists statements for compilation of TextureTest.cu: a short simple program …
…for testing the gl_texture class (Temporary). Compiles and runs (errors with glBegin())
Showing
3 changed files
with
205 additions
and
7 deletions
Show diff stats
CMakeLists.txt
... | ... | @@ -2,14 +2,27 @@ |
2 | 2 | cmake_minimum_required(VERSION 2.8) |
3 | 3 | |
4 | 4 | #Name your project here |
5 | -project(volume-spider) | |
5 | +project(Texture_Test) | |
6 | 6 | |
7 | 7 | #set the module directory |
8 | 8 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") |
9 | - | |
9 | +#MESSAGE("CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}) | |
10 | +#MESSAGE("CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}) | |
10 | 11 | #find cuda |
11 | 12 | find_package(CUDA REQUIRED) |
12 | 13 | |
14 | +#find glut | |
15 | +find_package(GLUT REQUIRED) | |
16 | + | |
17 | +#find glew | |
18 | +find_package(GLEW REQUIRED) | |
19 | + | |
20 | +#find OpenGL | |
21 | +find_package(OpenGL REQUIRED) | |
22 | + | |
23 | +#find Jpeg | |
24 | +find_package(JPEG REQUIRED) | |
25 | + | |
13 | 26 | #find BOOST - particularly the filesystem libraries |
14 | 27 | set(Boost_USE_STATIC_LIBS ON) |
15 | 28 | find_package(Boost 1.5.0 COMPONENTS filesystem system regex REQUIRED) |
... | ... | @@ -22,7 +35,16 @@ find_package(Threads) |
22 | 35 | find_package(X11) |
23 | 36 | |
24 | 37 | #include directories |
25 | -include_directories(${CUDA_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) | |
38 | +include_directories(${CUDA_INCLUDE_DIRS} | |
39 | + ${Boost_INCLUDE_DIRS} | |
40 | + ${OPENGL_INCLUDE_DIRS} | |
41 | + ${GLEW_INCLUDE_PATH} | |
42 | + ${GLUT_INCLUDE_DIRS} | |
43 | + ${JPEG_INCLUDE_DIRS} | |
44 | + ) | |
45 | + | |
46 | +#link_directories(${GLUT_LIBRARY_DIRS} ${OpenGL_LIBRARY_DIRS}) | |
47 | +#add_definitions(${GLUT_DEFINITIONS} ${OpenGL_DEFINITIONS}) | |
26 | 48 | |
27 | 49 | #Assign source files to the appropriate variables |
28 | 50 | file(GLOB SRC_CPP "*.cpp") |
... | ... | @@ -30,13 +52,19 @@ file(GLOB SRC_H "*.h") |
30 | 52 | file(GLOB SRC_CU "*.cu") |
31 | 53 | |
32 | 54 | #create an executable file |
33 | -cuda_add_executable(volume-spider | |
55 | +cuda_add_executable(Texture_Test | |
34 | 56 | ${SRC_H} |
35 | 57 | ${SRC_CPP} |
36 | 58 | ${SRC_CU}) |
37 | 59 | |
38 | 60 | #set the link libraries |
39 | -target_link_libraries(volume-spider | |
61 | +target_link_libraries(Texture_Test | |
40 | 62 | ${CMAKE_THREAD_LIBS_INIT} |
41 | 63 | ${X11_LIBRARIES} |
42 | - ${Boost_LIBRARIES}) | |
64 | + ${Boost_LIBRARIES} | |
65 | + ${OPENGL_gl_LIBRARY} | |
66 | + ${OPENGL_glu_LIBRARY} | |
67 | + ${GLEW_LIBRARY} | |
68 | + ${GLUT_glut_LIBRARY} | |
69 | + ${JPEG_LIBRARY} | |
70 | + ) | ... | ... |
1 | +#include <math.h> | |
2 | +#include <iostream> | |
3 | +#include <vector> | |
4 | +#include <GL/glut.h> | |
5 | +#include <GL/glext.h> | |
6 | +#include "gl/gl_texture.h" | |
7 | +#include "gl/error.h" | |
8 | + GLuint texID; | |
9 | + | |
10 | + GLfloat Normals[6][3] = | |
11 | + {{ -1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, | |
12 | + {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}}; | |
13 | + GLint faces[6][4] = | |
14 | + {{0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, | |
15 | + {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3}}; | |
16 | + GLfloat vertex[8][3] = | |
17 | + {{-1.0, -1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, | |
18 | + {-1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, | |
19 | + {1.0, 1.0, -1.0}, {1.0, 1.0, 1.0}}; | |
20 | + | |
21 | + | |
22 | +void | |
23 | +glInit(int w, int h) | |
24 | +{ | |
25 | + CHECK_OPENGL_ERROR | |
26 | +// glEnable(GL_TEXTURE_3D); | |
27 | + glEnable(GL_DEPTH_TEST); | |
28 | +// glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | |
29 | + glClearColor(0.0, 1.0, 1.0, 1.0); | |
30 | + glColor4d(0.0, 0.0, 0.0, 1.0); | |
31 | + glPointSize(3.0); | |
32 | + glShadeModel(GL_FLAT); | |
33 | + | |
34 | + glViewport(0, 0, (GLsizei) 720, (GLsizei) 720); | |
35 | + glMatrixMode(GL_PROJECTION); | |
36 | + glLoadIdentity(); | |
37 | + CHECK_OPENGL_ERROR | |
38 | +} | |
39 | + | |
40 | + | |
41 | +void | |
42 | +renderScene() | |
43 | + { | |
44 | + // glEnable(GL_TEXTURE_3D); | |
45 | + // glBindTexture(GL_TEXTURE_3D, texID); | |
46 | + CHECK_OPENGL_ERROR | |
47 | + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
48 | + //glLoadIdentity(); | |
49 | + //glTranslated(0.0, 0.0, 0.0); | |
50 | + //glRotated(-90, 1.0, 0.0, 0.0); | |
51 | + CHECK_OPENGL_ERROR | |
52 | + glBegin(GL_POINTS); | |
53 | + glVertex(0.0, 0.0, 0.0); | |
54 | + glVertex(0.0, 1.0, 0.0); | |
55 | + glVertex(1.0, 1.0, 0.0); | |
56 | + glVertex(1.0, 0.0, 0.0); | |
57 | +/* for (int i = 0; i < 6; i++) { | |
58 | + //first vertex | |
59 | + std::cout << "setting vertex 1 of face " << i | |
60 | + << " vertex located at " << | |
61 | + "[" << vertex[faces[i][0]][0] << "," | |
62 | + << vertex[faces[i][0]][1] << "," | |
63 | + << vertex[faces[i][0]][2] << "]" << std::endl; | |
64 | + glTexCoord3d(vertex[faces[i][0]][0], | |
65 | + vertex[faces[i][0]][1], | |
66 | + vertex[faces[i][0]][2]); | |
67 | + | |
68 | + glVertex3d(vertex[faces[i][0]][0], | |
69 | + vertex[faces[i][0]][1], | |
70 | + vertex[faces[i][0]][2]); | |
71 | + | |
72 | + //second vertex | |
73 | + glTexCoord3d(vertex[faces[i][1]][0], | |
74 | + vertex[faces[i][1]][1], | |
75 | + vertex[faces[i][1]][2]); | |
76 | + | |
77 | + glVertex3d(vertex[faces[i][1]][0], | |
78 | + vertex[faces[i][1]][1], | |
79 | + vertex[faces[i][1]][2]); | |
80 | + | |
81 | + //third vertex | |
82 | + glTexCoord3d(vertex[faces[i][2]][0], | |
83 | + vertex[faces[i][2]][1], | |
84 | + vertex[faces[i][2]][2]); | |
85 | + | |
86 | + glVertex3d(vertex[faces[i][2]][0], | |
87 | + vertex[faces[i][2]][1], | |
88 | + vertex[faces[i][2]][2]); | |
89 | + | |
90 | + //fourth vertex | |
91 | + glTexCoord3d(vertex[faces[i][3]][0], | |
92 | + vertex[faces[i][3]][1], | |
93 | + vertex[faces[i][3]][2]); | |
94 | + | |
95 | + glVertex3d(vertex[faces[i][3]][0], | |
96 | + vertex[faces[i][3]][1], | |
97 | + vertex[faces[i][3]][2]); | |
98 | + }*/ | |
99 | + glEnd(); | |
100 | + | |
101 | + CHECK_OPENGL_ERROR | |
102 | + glutSwapBuffers(); | |
103 | + | |
104 | + //glutPostRedisplay(); | |
105 | + } | |
106 | + | |
107 | + | |
108 | + | |
109 | +void | |
110 | +processKeys(unsigned char key, int x, int y) | |
111 | +{ | |
112 | + if (key == 27) | |
113 | + exit(0); | |
114 | +} | |
115 | + | |
116 | + | |
117 | +void | |
118 | +changeSize(int w, int h) | |
119 | +{ | |
120 | + if (h==0) | |
121 | + h=1; | |
122 | + float ratio = w*1.0/h; | |
123 | + CHECK_OPENGL_ERROR | |
124 | + glMatrixMode(GL_PROJECTION); | |
125 | + | |
126 | + glLoadIdentity(); | |
127 | + | |
128 | + glViewport(0,0,w,h); | |
129 | + | |
130 | + gluPerspective(90, 1, 0.1, 10.0); | |
131 | + | |
132 | + glMatrixMode(GL_MODELVIEW); | |
133 | + CHECK_OPENGL_ERROR | |
134 | +} | |
135 | + | |
136 | + | |
137 | +int | |
138 | +main(int argc, char **argv) | |
139 | +{ | |
140 | + CHECK_OPENGL_ERROR | |
141 | + /*stim::gl_texture<unsigned char> stack ("/home/pavel/Documents/Test_Data/"); | |
142 | + stack.createTexture(); | |
143 | + texID = stack.getTexture();*/ | |
144 | + //stack.save_images("test\\????.jpg"); | |
145 | + | |
146 | + std::cout << ("I have started an instance of the class") << std::endl; | |
147 | + | |
148 | + | |
149 | + CHECK_OPENGL_ERROR | |
150 | + glutInit(&argc, argv); | |
151 | + glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); | |
152 | + glutInitWindowSize(720, 720); | |
153 | + glutCreateWindow("gl_texture"); | |
154 | + std::cout << " Initialization is complete in Glut" << std::endl; | |
155 | + | |
156 | + CHECK_OPENGL_ERROR | |
157 | + glutKeyboardFunc(processKeys); | |
158 | + CHECK_OPENGL_ERROR | |
159 | + glutReshapeFunc(changeSize); | |
160 | + CHECK_OPENGL_ERROR | |
161 | + glutDisplayFunc(renderScene); | |
162 | + CHECK_OPENGL_ERROR | |
163 | + std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl; | |
164 | + glInit(5, 5); | |
165 | + CHECK_OPENGL_ERROR | |
166 | + glutMainLoop(); | |
167 | + CHECK_OPENGL_ERROR | |
168 | + return 0; | |
169 | +} | |
170 | + | ... | ... |