72ee146e
Pavel Govyadinov
added temporary f...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
GLfloat Normals[6][3] =
{{ -1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}};
GLint faces[6][4] =
{{0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
{4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3}};
GLfloat vertex[8][3] =
{{-1.0, -1.0, 1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0},
{-1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0},
{1.0, 1.0, -1.0}, {1.0, 1.0, 1.0}};
void
renderScene(void)
{
glEnable(GL_TEXTURE_3D);
glBindTexture(GL_TEXTURE_3D, texId);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glTranslate(0.0, -1.0, -2.4);
glBegin(GL_QUADS);
for (int i = 0; i < 6; i++) {
//first vertex
glTexCoord3d(vertex[faces[i][0]][0],
vertex[faces[i][0]][1],
vertex[faces[i][0]][2]);
glVertex3d(vertex[faces[i][0]][0],
vertex[faces[i][0]][1],
vertex[faces[i][0]][2]);
//second vertex
glTexCoord3d(vertex[faces[i][1]][0],
vertex[faces[i][1]][1],
vertex[faces[i][1]][2]);
glVertex3d(vertex[faces[i][1]][0],
vertex[faces[i][1]][1],
vertex[faces[i][1]][2]);
//third vertex
glTexCoord3d(vertex[faces[i][2]][0],
vertex[faces[i][2]][1],
vertex[faces[i][2]][2]);
glVertex3d(vertex[faces[i][2]][0],
vertex[faces[i][2]][1],
vertex[faces[i][2]][2]);
//fourth vertex
glTexCoord3d(vertex[faces[i][3]][0],
vertex[faces[i][3]][1],
vertex[faces[i][3]][2]);
glVertex3d(vertex[faces[i][3]][0],
vertex[faces[i][3]][1],
vertex[faces[i][3]][2]);
}
glEnd();
glutSwapBuffers();
}
}
void
processKeys(unsigned char key, int x, int y)
{
if (key == 27)
exit(0);
}
void
changeSize(int w, int h)
{
if (h==0)
h=1;
float ratio = w*1.0/h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,w,h);
gluPerspective(45.0, ratio, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
}
GLuint _texID;
int
main(int argc, char **argv)
{
stim::texture<unsigned char> stack("/home/pavel/Documents/Test_Data/");
stim::texture.CreateTexture();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(720, 720);
glutCreateWindow("gl_textures");
std::cerr << " Initialization is complete in Glut" << std::endl;
//Process keyboard commands (exit on esc)
glutKeyboardFunc(&processKeys);
glutReshapeFunc(&changeSize);
glutDisplayFunc(&renderScene);
std::cerr << " Keyboard and Reshape is complete in Glut" << std::endl;
//Render Scene and such.
std::cerr << " Loaded Image " << std::endl;
glutMainLoop();
return 0;
}
|