-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube_texture.cpp
170 lines (140 loc) · 3.37 KB
/
cube_texture.cpp
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cstdlib>
#include "sdlglutils.h"
void Dessiner();
double angleZ = 0;
double angleX = 0;
GLuint texture1;
GLuint texture2;
int main(int argc, char *argv[])
{
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
SDL_WM_SetCaption("SDL GL Application", NULL);
SDL_SetVideoMode(1920, 1080, 32, SDL_OPENGL);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(70,(double)1920/1080,1,1000);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
Dessiner();
Uint32 last_time = SDL_GetTicks();
Uint32 current_time,ellapsed_time;
Uint32 start_time;
texture1 = loadTexture("stainedglass05.jpg");
texture2 = loadTexture("metal090r.jpg");
for (;;)
{
start_time = SDL_GetTicks();
while (SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
exit(0);
break;
}
}
current_time = SDL_GetTicks();
ellapsed_time = current_time - last_time;
last_time = current_time;
angleZ += 0.05 * ellapsed_time;
angleX += 0.05 * ellapsed_time;
Dessiner();
ellapsed_time = SDL_GetTicks() - start_time;
if (ellapsed_time < 10)
{
SDL_Delay(10 - ellapsed_time);
}
}
return 0;
}
void Dessiner()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
gluLookAt(3,4,2,0,0,0,0,0,1);
glBindTexture(GL_TEXTURE_2D, texture2);
glBegin(GL_QUADS);
glColor3ub(255,0, 0);
glTexCoord2i(0,0); glVertex3i(-10,-10,-1);
glColor3ub(255,255, 255);
glTexCoord2i(10,0); glVertex3i(10,-10,-1);
glColor3ub(255,255, 255);
glTexCoord2i(10,10); glVertex3i(10,10,-1);
glTexCoord2i(0,10); glVertex3i(-10,10,-1);
glEnd();
glRotated(angleZ,0,0,1);
glRotated(angleX,1,0,0);
glBindTexture(GL_TEXTURE_2D, texture1);
/*
glBegin(GL_QUADS);
glTexCoord2d(0,1); glVertex3d(1,1,1);
glTexCoord2d(0,0); glVertex3d(1,1,-1);
glTexCoord2d(1,0); glVertex3d(-1,1,-1);
glTexCoord2d(1,1); glVertex3d(-1,1,1);
glEnd();
*/
glBegin(GL_QUADS);
glTexCoord2d(0,1);
glVertex3d(1,1,1);
glTexCoord2d(0,0);
glVertex3d(1,1,-1);
glTexCoord2d(1,0);
glVertex3d(-1,1,-1);
glTexCoord2d(1,1);
glVertex3d(-1,1,1);
glTexCoord2d(0,1);
glVertex3d(1,-1,1);
glTexCoord2d(0,0);
glVertex3d(1,-1,-1);
glTexCoord2d(1,0);
glVertex3d(1,1,-1);
glTexCoord2d(1,1);
glVertex3d(1,1,1);
//face bleue
glTexCoord2d(0,1);
glVertex3d(-1,-1,1);
glTexCoord2d(0,0);
glVertex3d(-1,-1,-1);
glTexCoord2d(1,0);
glVertex3d(1,-1,-1);
glTexCoord2d(1,1);
glVertex3d(1,-1,1);
//face jaune
//glColor3ub(255,255,0);
glTexCoord2d(0,1);
glVertex3d(-1,1,1);
glTexCoord2d(0,0);
glVertex3d(-1,1,-1);
glTexCoord2d(1,0);
glVertex3d(-1,-1,-1);
glTexCoord2d(1,1);
glVertex3d(-1,-1,1);
//face cyan
//glColor3ub(0,255,255);
glTexCoord2d(0,0);
glVertex3d(1,1,-1);
glTexCoord2d(0,1);
glVertex3d(1,-1,-1);
glTexCoord2d(1,1);
glVertex3d(-1,-1,-1);
glTexCoord2d(1,0);
glVertex3d(-1,1,-1);
//glColor3ub(255,0,255); //face magenta
glTexCoord2d(0,1);
glVertex3d(1,-1,1);
glTexCoord2d(0,0);
glVertex3d(1,1,1);
glTexCoord2d(1,0);
glVertex3d(-1,1,1);
glTexCoord2d(1,1);
glVertex3d(-1,-1,1);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
}