~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/Core/RendererInterface/OGL_Draw2D.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-04-09 02:04:25 UTC
  • Revision ID: package-import@ubuntu.com-20130409020425-a7fl9xk4diamw6di
Tags: upstream-1.3.1+repack
Import upstream version 1.3.1+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
 
 
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
 
4
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
5
 
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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/>.
 
19
 
 
20
 
 
21
        Web Site: http://www.viewizard.com/
 
22
        Project: http://sourceforge.net/projects/openastromenace/
 
23
        E-mail: viewizard@viewizard.com
 
24
 
 
25
*************************************************************************************/
 
26
 
 
27
 
 
28
#include "RendererInterface.h"
 
29
 
 
30
 
 
31
 
 
32
 
 
33
 
 
34
 
 
35
//------------------------------------------------------------------------------------
 
36
// Переход на 2D режима вывода
 
37
//------------------------------------------------------------------------------------
 
38
void vw_Start2DMode(float nZ1, float nZ2)
 
39
{
 
40
    // запоминаем состояние флагов
 
41
        glPushAttrib(GL_ENABLE_BIT);
 
42
    // и выключаем "ненужные"
 
43
        glDisable(GL_CULL_FACE);
 
44
    glDisable(GL_DEPTH_TEST);
 
45
 
 
46
        // берем размер вьюпорта
 
47
        int X, Y, W, H;
 
48
        vw_GetViewport(&X, &Y, &W, &H);
 
49
 
 
50
        // переводим его в флоат для расчетов (нужно чтобы результаты были флоат)
 
51
        float AWw = W*1.0f;
 
52
        float AHw = H*1.0f;
 
53
 
 
54
        glMatrixMode(GL_PROJECTION);                                                            //select the projection matrix
 
55
        glPushMatrix();                                                                                         //store the projection matrix
 
56
        glLoadIdentity();                                                                                       //reset the projection matrix
 
57
 
 
58
        // смотрим, была ли установка на фиксированный внутренний размер
 
59
        float AW;
 
60
        float AH;
 
61
        bool ASpresent=false;
 
62
        ASpresent = vw_GetAspectWH(&AW, &AH);
 
63
 
 
64
 
 
65
        if (ASpresent)
 
66
                glOrtho(X*(AW/AWw), (X+W)*(AW/AWw), Y*(AH/AHw), (Y+H)*(AH/AHw), nZ1, nZ2);
 
67
        else
 
68
                glOrtho(0, AWw, 0, AHw, nZ1, nZ2);      //set up an ortho screen
 
69
 
 
70
        glMatrixMode(GL_MODELVIEW);                             //select the modelview matrix
 
71
        glPushMatrix();
 
72
        glLoadIdentity();
 
73
 
 
74
}
 
75
 
 
76
 
 
77
 
 
78
//------------------------------------------------------------------------------------
 
79
// Возвращение в обычный (3D) режим вывода
 
80
//------------------------------------------------------------------------------------
 
81
void vw_End2DMode()
 
82
{
 
83
        glMatrixMode(GL_MODELVIEW);                             //select the modelview matrix
 
84
        glPopMatrix();
 
85
 
 
86
        glMatrixMode(GL_PROJECTION);                    //select the projection matrix
 
87
        glPopMatrix();                                                  //restore the old projection matrix
 
88
 
 
89
        glMatrixMode(GL_MODELVIEW);                             //select the modelview matrix
 
90
 
 
91
    // восстанавливаем флаги
 
92
        glPopAttrib();
 
93
}
 
94
 
 
95
 
 
96
 
 
97
 
 
98
 
 
99
 
 
100
//------------------------------------------------------------------------------------
 
101
// Прорисовка в 2д
 
102
//------------------------------------------------------------------------------------
 
103
void vw_Draw(int X, int Y, RECT *SrcRest, eTexture *Tex, bool Alpha, float RotateAngle, int DrawCorner)
 
104
{
 
105
        if (Tex == 0) return;
 
106
 
 
107
        float AW;
 
108
        float AH;
 
109
        bool ASpresent=false;
 
110
        ASpresent = vw_GetAspectWH(&AW, &AH);
 
111
 
 
112
        int W, H;
 
113
        vw_GetViewport(0, 0, &W, &H);
 
114
        float AHw = H*1.0f;
 
115
 
 
116
        // Установка текстуры и ее свойств...
 
117
        vw_SetTexture(0, Tex);
 
118
        vw_SetTextureBlend(Alpha, RI_BLEND_SRCALPHA, RI_BLEND_INVSRCALPHA);
 
119
 
 
120
 
 
121
        // Вычисление поправки по У в зависимости от DrawCorner
 
122
        // - расположения угла начала координат
 
123
        float tmpPosY = 0;
 
124
        // изменяем только в случае RI_UL_CORNER
 
125
        if (DrawCorner == RI_UL_CORNER)
 
126
        {
 
127
                if (ASpresent) tmpPosY = (AH - Y - Y - (SrcRest->bottom - SrcRest->top));
 
128
                else tmpPosY = (AHw - Y - Y - (SrcRest->bottom - SrcRest->top));
 
129
        }
 
130
 
 
131
 
 
132
        float ImageHeight = Tex->Height*1.0f;
 
133
        float ImageWidth = Tex->Width*1.0f;
 
134
 
 
135
        float FrameHeight = (SrcRest->bottom*1.0f)/ImageHeight;
 
136
        float FrameWidth = (SrcRest->right*1.0f)/ImageWidth;
 
137
 
 
138
        float Yst = (SrcRest->top)/ImageHeight;
 
139
        float Xst = (SrcRest->left)/ImageWidth;
 
140
 
 
141
 
 
142
        // буфер для последовательности RI_TRIANGLE_STRIP
 
143
        // войдет RI_2f_XYZ | RI_2f_TEX
 
144
        float *tmp = 0;
 
145
        tmp = new float[(2+2)*4]; if (tmp == 0) return;
 
146
        int k=0;
 
147
 
 
148
        tmp[k++] = X;
 
149
        tmp[k++] = Y +tmpPosY + (SrcRest->bottom - SrcRest->top);
 
150
        tmp[k++] = Xst;
 
151
        tmp[k++] = 1.0f-Yst;
 
152
 
 
153
        tmp[k++] = X;
 
154
        tmp[k++] = Y +tmpPosY;
 
155
        tmp[k++] = Xst;
 
156
        tmp[k++] = 1.0f-FrameHeight;
 
157
 
 
158
        tmp[k++] = X + (SrcRest->right - SrcRest->left);
 
159
        tmp[k++] = Y +tmpPosY + (SrcRest->bottom - SrcRest->top);
 
160
        tmp[k++] = FrameWidth;
 
161
        tmp[k++] = 1.0f-Yst;
 
162
 
 
163
        tmp[k++] = X + (SrcRest->right - SrcRest->left);
 
164
        tmp[k++] = Y +tmpPosY;
 
165
        tmp[k++] = FrameWidth;
 
166
        tmp[k++] = 1.0f-FrameHeight;
 
167
 
 
168
        glPushMatrix();
 
169
        glRotatef(RotateAngle, 0, 0, 1);
 
170
 
 
171
        vw_SendVertices(RI_TRIANGLE_STRIP, 4, RI_2f_XY | RI_1_TEX, tmp, 4*sizeof(float));
 
172
        glPopMatrix();
 
173
 
 
174
 
 
175
        if (tmp != 0){delete [] tmp; tmp = 0;}
 
176
        vw_SetTextureBlend(false, 0, 0);
 
177
        vw_BindTexture(0, 0);
 
178
}
 
179
 
 
180
 
 
181
 
 
182
 
 
183
 
 
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)
 
188
{
 
189
 
 
190
        if (Tex == 0) return;
 
191
        if (Transp <= 0.0f) return;
 
192
        if (Transp > 1.0f) Transp = 1.0f;
 
193
 
 
194
        float AW;
 
195
        float AH;
 
196
        bool ASpresent=false;
 
197
        ASpresent = vw_GetAspectWH(&AW, &AH);
 
198
 
 
199
        int W, H;
 
200
        vw_GetViewport(0, 0, &W, &H);
 
201
        float AHw = H*1.0f;
 
202
 
 
203
        int X = DstRest->left;
 
204
        int Y = DstRest->top;
 
205
 
 
206
        // Установка текстуры и ее свойств...
 
207
        vw_SetTexture(0, Tex);
 
208
        vw_SetTextureBlend(Alpha, RI_BLEND_SRCALPHA, RI_BLEND_INVSRCALPHA);
 
209
 
 
210
        // Вычисление поправки по У в зависимости от DrawCorner
 
211
        // - расположения угла начала координат
 
212
        float tmpPosY = 0;
 
213
        // изменяем только в случае RI_UL_CORNER
 
214
        if (DrawCorner == RI_UL_CORNER)
 
215
        {
 
216
                if (ASpresent) tmpPosY = (AH - Y - Y - (DstRest->bottom - DstRest->top));
 
217
                else tmpPosY = (AHw - Y - Y - (DstRest->bottom - DstRest->top));
 
218
        }
 
219
 
 
220
 
 
221
 
 
222
        float ImageHeight = Tex->Height*1.0f;
 
223
        float ImageWidth = Tex->Width*1.0f;
 
224
 
 
225
        float FrameHeight = (SrcRest->bottom*1.0f )/ImageHeight;
 
226
        float FrameWidth = (SrcRest->right*1.0f )/ImageWidth;
 
227
 
 
228
        float Yst = (SrcRest->top*1.0f)/ImageHeight;
 
229
        float Xst = (SrcRest->left*1.0f)/ImageWidth;
 
230
 
 
231
 
 
232
        vw_SetColor(R, G, B, Transp);
 
233
 
 
234
        // буфер для последовательности RI_TRIANGLE_STRIP
 
235
        // войдет RI_2f_XYZ | RI_2f_TEX
 
236
        float *tmp = 0;
 
237
        tmp = new float[(2+2)*4]; if (tmp == 0) return;
 
238
        int k=0;
 
239
 
 
240
        tmp[k++] = X;
 
241
        tmp[k++] = Y +tmpPosY + (DstRest->bottom - DstRest->top);
 
242
        tmp[k++] = Xst;
 
243
        tmp[k++] = 1.0f-Yst;
 
244
 
 
245
        tmp[k++] = X;
 
246
        tmp[k++] = Y +tmpPosY;
 
247
        tmp[k++] = Xst;
 
248
        tmp[k++] = 1.0f-FrameHeight;
 
249
 
 
250
        tmp[k++] = X + (DstRest->right - DstRest->left);
 
251
        tmp[k++] = Y +tmpPosY + (DstRest->bottom - DstRest->top);
 
252
        tmp[k++] = FrameWidth;
 
253
        tmp[k++] = 1.0f-Yst;
 
254
 
 
255
        tmp[k++] = X + (DstRest->right - DstRest->left);
 
256
        tmp[k++] = Y +tmpPosY;
 
257
        tmp[k++] = FrameWidth;
 
258
        tmp[k++] = 1.0f-FrameHeight;
 
259
 
 
260
 
 
261
        glPushMatrix();
 
262
        glRotatef(RotateAngle, 0, 0, 1);
 
263
 
 
264
        vw_SendVertices(RI_TRIANGLE_STRIP, 4, RI_2f_XY | RI_1_TEX, tmp, 4*sizeof(float));
 
265
 
 
266
        glPopMatrix();
 
267
 
 
268
 
 
269
 
 
270
        if (tmp != 0){delete [] tmp; tmp = 0;}
 
271
 
 
272
        vw_SetTextureBlend(false, 0, 0);
 
273
        vw_SetColor(1.0f, 1.0f, 1.0f, 1.0f);
 
274
        vw_BindTexture(0, 0);
 
275
 
 
276
}