Skip to content
This repository
Newer
Older
100644 126 lines (89 sloc) 3.85 kb
2b48c0e8 » Frictional Games
2010-05-12 Initial Open Source Release
1 /*
2 * Copyright (C) 2006-2010 - Frictional Games
3 *
4 * This file is part of Penumbra Overture.
5 *
6 * Penumbra Overture is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Penumbra Overture is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Penumbra Overture. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "GraphicsHelper.h"
20
21 #include "Init.h"
22
23 //-----------------------------------------------------------------------
24
25 //////////////////////////////////////////////////////////////////////////
26 // CONSTRUCTORS
27 //////////////////////////////////////////////////////////////////////////
28
29 //-----------------------------------------------------------------------
30
31 cGraphicsHelper::cGraphicsHelper(cInit *apInit)
32 {
33 mpInit = apInit;
34
35 mpLowLevelGfx = mpInit->mpGame->GetGraphics()->GetLowLevel();
36 mpTexManager = mpInit->mpGame->GetResources()->GetTextureManager();
37
38 mpDrawer = mpInit->mpGame->GetGraphics()->GetDrawer();
39
40 mpFont =mpInit->mpGame->GetResources()->GetFontManager()->CreateFontData("font_menu_small.fnt");
41
42 mvVtx.resize(4);
43 }
44
45 cGraphicsHelper::~cGraphicsHelper()
46 {
47
48 }
49
50 //-----------------------------------------------------------------------
51
52 //////////////////////////////////////////////////////////////////////////
53 // PUBLIC METHODS
54 //////////////////////////////////////////////////////////////////////////
55
56 //-----------------------------------------------------------------------
57
58 void cGraphicsHelper::ClearScreen(const cColor &aColor)
59 {
60 mpLowLevelGfx->SetClearColor(aColor);
61 mpLowLevelGfx->ClearScreen();
62 }
63
64 //-----------------------------------------------------------------------
65
66 void cGraphicsHelper::DrawTexture(iTexture *apTex, const cVector3f& avPos, const cVector3f& avSize,
67 const cColor &aColor)
68 {
69 mpLowLevelGfx->SetDepthTestActive(false);
70 mpLowLevelGfx->PushMatrix(eMatrix_ModelView);
71 mpLowLevelGfx->SetIdentityMatrix(eMatrix_ModelView);
72 mpLowLevelGfx->SetOrthoProjection(mpLowLevelGfx->GetVirtualSize(),-1000,1000);
73
74 mvVtx[0] = cVertex(avPos + cVector3f(0,0,0), cVector2f(0.01f,0.01f),aColor );
75 mvVtx[1] = cVertex(avPos + cVector3f(avSize.x,0,0), cVector2f(0.99f,0.01f),aColor);
76 mvVtx[2] = cVertex(avPos + cVector3f(avSize.x,avSize.y,0),cVector2f(0.99f,0.99f),aColor);
77 mvVtx[3] = cVertex(avPos + cVector3f(0,avSize.y,0), cVector2f(0.01f,0.99f),aColor);
78
79 mpLowLevelGfx->SetBlendActive(false);
80
81 for(int i=0;i<6;++i) mpLowLevelGfx->SetTexture(i,NULL);
82
83 mpLowLevelGfx->SetTexture(0,apTex);
84
85 mpLowLevelGfx->DrawQuad(mvVtx);
86
87 mpLowLevelGfx->SetTexture(0,NULL);
88
89 mpLowLevelGfx->PopMatrix(eMatrix_ModelView);
90 }
91
92 //-----------------------------------------------------------------------
93
94 void cGraphicsHelper::DrawLoadingScreen(const tString &asFile)
95 {
96 iTexture *pTex= NULL;
97
98 if(asFile != "")
99 pTex = mpTexManager->Create2D(asFile,false);
100
101 if(pTex || asFile == "")
102 {
103 ClearScreen(cColor(0,0));
104
105 if(pTex) DrawTexture(pTex,cVector3f(0,0,0),cVector2f(800,600),cColor(1,1));
106
107 mpFont->Draw(cVector3f(400,300,50),22,cColor(1,1),eFontAlign_Center,
108 _W("%ls"),kTranslate("LoadTexts", "Loading").c_str());
109
110 mpDrawer->DrawAll();
111
112 SwapBuffers();
113 }
114
115 if(pTex) mpTexManager->Destroy(pTex);
116 }
117
118 //-----------------------------------------------------------------------
119
120 void cGraphicsHelper::SwapBuffers()
121 {
122 mpLowLevelGfx->SwapBuffers();
123 }
124
125
126 //-----------------------------------------------------------------------
Something went wrong with that request. Please try again.