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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
| #include <windows.h> // Header File For Windows
#include <gl.h> // Header File For The OpenGL32 Library
#include <glu.h> // Header File For The GLu32 Library
#include <glaux.h> // Header File For The Glaux Library
#include <stdio.h> // Header File For Standard Input/Output
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
GLuint texture[20]; // Место для двух текстур
GLfloat rtri; // Angle For The Triangle ( NEW )
GLfloat rquad; // Angle For The Quad ( NEW )
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}
return NULL; // If Load Failed Return NULL
}
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("test.bmp"))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
if (TextureImage[1]=LoadBMP("test1.bmp"))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(2, &texture[1]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
}
if (TextureImage[1]) // If Texture Exists
{
if (TextureImage[1]->data) // If Texture Image Exists
{
free(TextureImage[1]->data); // Free The Texture Image Memory
}
free(TextureImage[1]); // Free The Image Structure
}
return Status; // Return The Status
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE
}
glEnable(GL_TEXTURE_2D); // Разрешение наложение текстуры
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,1.0f,-7.0f); // Сдвиг влево и вглубь экрана
glBindTexture(GL_TEXTURE_2D, texture[0]);
//glRotatef(rtri,1.0f,1.0f,0.0f); // Вращение пирамиды по оси Y
glBegin(GL_TRIANGLES); // Начало рисования пирамиды
glTexCoord2f(0.5f, 1.0f);glVertex3f( 0.0f, 1.0f, 0.0f); // Верх треугольника (Передняя)
glTexCoord2f(0.0f, 0.0f);glVertex3f(-1.0f,-1.0f, 1.0f); // Левая точка
glTexCoord2f(1.0f, 0.0f);glVertex3f( 1.0f,-1.0f, 1.0f); // Правая точка
glTexCoord2f(0.5f, 1.0f);glVertex3f( 0.0f, 1.0f, 0.0f); // Верх треугольника (Правая)
glTexCoord2f(0.0f, 0.0f);glVertex3f( 1.0f,-1.0f, 1.0f); // Лево треугольника (Правая)
glTexCoord2f(1.0f, 0.0f);glVertex3f( 1.0f,-1.0f, -1.0f); // Право треугольника (Правая)
glTexCoord2f(0.5f, 1.0f);glVertex3f( 0.0f, 1.0f, 0.0f); // Низ треугольника (Сзади)
glTexCoord2f(0.0f, 0.0f);glVertex3f( 1.0f,-1.0f, -1.0f); // Лево треугольника (Сзади)
glTexCoord2f(1.0f, 0.0f);glVertex3f(-1.0f,-1.0f, -1.0f); // Право треугольника (Сзади)
glTexCoord2f(0.5f, 1.0f);glVertex3f( 0.0f, 1.0f, 0.0f); // Низ треугольника (Лево)
glTexCoord2f(0.0f, 0.0f);glVertex3f(-1.0f,-1.0f,-1.0f); // Лево треугольника (Лево)
glTexCoord2f(1.0f, 0.0f);glVertex3f(-1.0f,-1.0f, 1.0f); // Право треугольника (Лево)
glEnd(); // Done Drawing The Triangle
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,1.0f,-7.0f);
//glBindTexture(GL_TEXTURE_2D, texture[1]);// Сдвиг влево и вглубь экрана
//glRotatef(rtri,1.0f,1.0f,0.0f); // Вращение пирамиды по оси Y
glBegin(GL_QUADS);
glVertex3f( 1.0f, -1.0f, 1.0f); // Верх лево
glVertex3f(-1.0f,-1.0f, 1.0f); // Низ лево
glVertex3f( -1.0f,-3.0f, 1.0f); // Низ право
glVertex3f( 1.0f, -3.0f, 1.0f); // Верх право
glVertex3f( 1.0f, -1.0f, -1.0f); // Верх лево
glVertex3f(1.0f,-1.0f, 1.0f); // Верх право
glVertex3f( 1.0f,-3.0f, 1.0f); // Низ право
glVertex3f( 1.0f, -3.0f, -1.0f); // Низ право
glVertex3f( -1.0f, -1.0f, 1.0f); // Верх лево
glVertex3f(-1.0f,-1.0f, -1.0f); // Верх лево
glVertex3f( -1.0f,-3.0f, -1.0f); //
glVertex3f( -1.0f, -3.0f, 1.0f); // Верх треугольника (Правая)
glVertex3f( -1.0f, -1.0f, -1.0f); // Верх треугольника (Передняя)
glVertex3f(-1.0f,-3.0f, -1.0f); // Левая точка
glVertex3f( 1.0f,-3.0f, -1.0f); // Правая точка
glVertex3f( 1.0f, -1.0f, -1.0f); // Верх треугольника (Правая)
glVertex3f( 1.0f, -3.0f, -1.0f); // Верх треугольника (Передняя)
glVertex3f(-1.0f,-3.0f, -1.0f); // Левая точка
glVertex3f( -1.0f,-3.0f, 1.0f); // Правая точка
glVertex3f( 1.0f, -3.0f, 1.0f); // Верх треугольника (Правая)
glEnd();
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-40.0f); // Сдвиг влево и вглубь экрана // Вращение пирамиды по оси Y
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS); // Зеленый цвет
glTexCoord2f(1.0f, 1.0f);glVertex3f( 20.0f, 20.0f, 1.0f); // Верх треугольника (Передняя)
glTexCoord2f(0.0f, 1.0f);glVertex3f(-20.0f,20.0f, 1.0f); // Левая точка
glTexCoord2f(0.0f, 0.0f);glVertex3f( -20.0f,-20.0f, 1.0f); // Правая точка
glTexCoord2f(1.0f, 0.0f);glVertex3f( 20.0f, -20.0f, 1.0f); // Верх треугольника (Правая)
glEnd();
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(1.5f,1.0f,-7.0f);
glBegin(GL_QUADS);
glVertex3f( 0.7f, -2.0f, 1.0f); // Верх лево
glVertex3f(0.2f,-2.0f, 1.0f); // Низ лево
glVertex3f( 0.2f,-3.0f, 1.0f); // Низ право
glVertex3f( 0.7f, -3.0f, 1.0f); // Верх право
glEnd();
rtri+=0.2f;
rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )
return TRUE; // Keep Going
} |