1
/************************************************************************************
3
AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
4
Copyright © 2006-2012 Michael Kurinnoy, Viewizard
7
AstroMenace is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
AstroMenace is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
21
Web Site: http://www.viewizard.com/
22
Project: http://sourceforge.net/projects/openastromenace/
23
E-mail: viewizard@viewizard.com
25
*************************************************************************************/
28
#include "RendererInterface.h"
35
//------------------------------------------------------------------------------------
36
// Переход на 2D режима вывода
37
//------------------------------------------------------------------------------------
38
void vw_Start2DMode(float nZ1, float nZ2)
40
// запоминаем состояние флагов
41
glPushAttrib(GL_ENABLE_BIT);
42
// и выключаем "ненужные"
43
glDisable(GL_CULL_FACE);
44
glDisable(GL_DEPTH_TEST);
46
// берем размер вьюпорта
48
vw_GetViewport(&X, &Y, &W, &H);
50
// переводим его в флоат для расчетов (нужно чтобы результаты были флоат)
54
glMatrixMode(GL_PROJECTION); //select the projection matrix
55
glPushMatrix(); //store the projection matrix
56
glLoadIdentity(); //reset the projection matrix
58
// смотрим, была ли установка на фиксированный внутренний размер
62
ASpresent = vw_GetAspectWH(&AW, &AH);
66
glOrtho(X*(AW/AWw), (X+W)*(AW/AWw), Y*(AH/AHw), (Y+H)*(AH/AHw), nZ1, nZ2);
68
glOrtho(0, AWw, 0, AHw, nZ1, nZ2); //set up an ortho screen
70
glMatrixMode(GL_MODELVIEW); //select the modelview matrix
78
//------------------------------------------------------------------------------------
79
// Возвращение в обычный (3D) режим вывода
80
//------------------------------------------------------------------------------------
83
glMatrixMode(GL_MODELVIEW); //select the modelview matrix
86
glMatrixMode(GL_PROJECTION); //select the projection matrix
87
glPopMatrix(); //restore the old projection matrix
89
glMatrixMode(GL_MODELVIEW); //select the modelview matrix
91
// восстанавливаем флаги
100
//------------------------------------------------------------------------------------
102
//------------------------------------------------------------------------------------
103
void vw_Draw(int X, int Y, RECT *SrcRest, eTexture *Tex, bool Alpha, float RotateAngle, int DrawCorner)
105
if (Tex == 0) return;
109
bool ASpresent=false;
110
ASpresent = vw_GetAspectWH(&AW, &AH);
113
vw_GetViewport(0, 0, &W, &H);
116
// Установка текстуры и ее свойств...
117
vw_SetTexture(0, Tex);
118
vw_SetTextureBlend(Alpha, RI_BLEND_SRCALPHA, RI_BLEND_INVSRCALPHA);
121
// Вычисление поправки по У в зависимости от DrawCorner
122
// - расположения угла начала координат
124
// изменяем только в случае RI_UL_CORNER
125
if (DrawCorner == RI_UL_CORNER)
127
if (ASpresent) tmpPosY = (AH - Y - Y - (SrcRest->bottom - SrcRest->top));
128
else tmpPosY = (AHw - Y - Y - (SrcRest->bottom - SrcRest->top));
132
float ImageHeight = Tex->Height*1.0f;
133
float ImageWidth = Tex->Width*1.0f;
135
float FrameHeight = (SrcRest->bottom*1.0f)/ImageHeight;
136
float FrameWidth = (SrcRest->right*1.0f)/ImageWidth;
138
float Yst = (SrcRest->top)/ImageHeight;
139
float Xst = (SrcRest->left)/ImageWidth;
142
// буфер для последовательности RI_TRIANGLE_STRIP
143
// войдет RI_2f_XYZ | RI_2f_TEX
145
tmp = new float[(2+2)*4]; if (tmp == 0) return;
149
tmp[k++] = Y +tmpPosY + (SrcRest->bottom - SrcRest->top);
154
tmp[k++] = Y +tmpPosY;
156
tmp[k++] = 1.0f-FrameHeight;
158
tmp[k++] = X + (SrcRest->right - SrcRest->left);
159
tmp[k++] = Y +tmpPosY + (SrcRest->bottom - SrcRest->top);
160
tmp[k++] = FrameWidth;
163
tmp[k++] = X + (SrcRest->right - SrcRest->left);
164
tmp[k++] = Y +tmpPosY;
165
tmp[k++] = FrameWidth;
166
tmp[k++] = 1.0f-FrameHeight;
169
glRotatef(RotateAngle, 0, 0, 1);
171
vw_SendVertices(RI_TRIANGLE_STRIP, 4, RI_2f_XY | RI_1_TEX, tmp, 4*sizeof(float));
175
if (tmp != 0){delete [] tmp; tmp = 0;}
176
vw_SetTextureBlend(false, 0, 0);
177
vw_BindTexture(0, 0);
184
//------------------------------------------------------------------------------------
185
// Прорисовка в 2д с прозрачностью
186
//------------------------------------------------------------------------------------
187
void vw_DrawTransparent(RECT *DstRest, RECT *SrcRest, eTexture *Tex, bool Alpha, float Transp, float RotateAngle, int DrawCorner, float R, float G, float B)
190
if (Tex == 0) return;
191
if (Transp <= 0.0f) return;
192
if (Transp > 1.0f) Transp = 1.0f;
196
bool ASpresent=false;
197
ASpresent = vw_GetAspectWH(&AW, &AH);
200
vw_GetViewport(0, 0, &W, &H);
203
int X = DstRest->left;
204
int Y = DstRest->top;
206
// Установка текстуры и ее свойств...
207
vw_SetTexture(0, Tex);
208
vw_SetTextureBlend(Alpha, RI_BLEND_SRCALPHA, RI_BLEND_INVSRCALPHA);
210
// Вычисление поправки по У в зависимости от DrawCorner
211
// - расположения угла начала координат
213
// изменяем только в случае RI_UL_CORNER
214
if (DrawCorner == RI_UL_CORNER)
216
if (ASpresent) tmpPosY = (AH - Y - Y - (DstRest->bottom - DstRest->top));
217
else tmpPosY = (AHw - Y - Y - (DstRest->bottom - DstRest->top));
222
float ImageHeight = Tex->Height*1.0f;
223
float ImageWidth = Tex->Width*1.0f;
225
float FrameHeight = (SrcRest->bottom*1.0f )/ImageHeight;
226
float FrameWidth = (SrcRest->right*1.0f )/ImageWidth;
228
float Yst = (SrcRest->top*1.0f)/ImageHeight;
229
float Xst = (SrcRest->left*1.0f)/ImageWidth;
232
vw_SetColor(R, G, B, Transp);
234
// буфер для последовательности RI_TRIANGLE_STRIP
235
// войдет RI_2f_XYZ | RI_2f_TEX
237
tmp = new float[(2+2)*4]; if (tmp == 0) return;
241
tmp[k++] = Y +tmpPosY + (DstRest->bottom - DstRest->top);
246
tmp[k++] = Y +tmpPosY;
248
tmp[k++] = 1.0f-FrameHeight;
250
tmp[k++] = X + (DstRest->right - DstRest->left);
251
tmp[k++] = Y +tmpPosY + (DstRest->bottom - DstRest->top);
252
tmp[k++] = FrameWidth;
255
tmp[k++] = X + (DstRest->right - DstRest->left);
256
tmp[k++] = Y +tmpPosY;
257
tmp[k++] = FrameWidth;
258
tmp[k++] = 1.0f-FrameHeight;
262
glRotatef(RotateAngle, 0, 0, 1);
264
vw_SendVertices(RI_TRIANGLE_STRIP, 4, RI_2f_XY | RI_1_TEX, tmp, 4*sizeof(float));
270
if (tmp != 0){delete [] tmp; tmp = 0;}
272
vw_SetTextureBlend(false, 0, 0);
273
vw_SetColor(1.0f, 1.0f, 1.0f, 1.0f);
274
vw_BindTexture(0, 0);