Angel 3.2
A 2D Game Prototyping Engine
HUDActor.cpp
1 
2 // Copyright (C) 2008-2013, Shane Liesegang
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of the copyright holder nor the names of any
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
29 
30 #include "stdafx.h"
31 #include "../Actors/HUDActor.h"
32 
33 #include "../Infrastructure/VecStructs.h"
34 #include "../Infrastructure/Camera.h"
35 #include "../Util/MathUtil.h"
36 #include "../Infrastructure/Log.h"
37 
39 {
40  Vec2i winDimensions;
41  winDimensions.X = theCamera.GetWindowWidth();
42  winDimensions.Y = theCamera.GetWindowHeight();
43  float pixelY = winDimensions.Y - _position.Y;
44 
45  //set up projection
46  glMatrixMode(GL_PROJECTION);
47  glPushMatrix();
48  glLoadIdentity();
49  gluOrtho2D(0, winDimensions.X, 0, winDimensions.Y);
50 
51  //set up modelview
52  glMatrixMode(GL_MODELVIEW);
53  glPushMatrix();
54  glLoadIdentity();
55  glTranslatef(_position.X, pixelY, 0);
56  glRotatef(_rotation, 0, 0, 1);
57  glScalef(_size.X, _size.Y, 1.0f);
58  glColor4f(_color.R, _color.G, _color.B, _color.A);
59 
60  int textureReference = _spriteTextureReferences[_spriteCurrentFrame];
61  if (textureReference >= 0)
62  {
63  glEnable(GL_TEXTURE_2D);
64  glBindTexture(GL_TEXTURE_2D, textureReference);
65  }
66 
67  switch( _drawShape )
68  {
69  default:
70  case ADS_Square:
71  glEnableClientState(GL_VERTEX_ARRAY);
72  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
73  glVertexPointer(2, GL_FLOAT, 0, _squareVertices);
74  glTexCoordPointer(2, GL_FLOAT, 0, _UV);
75  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
76  break;
77 
78  case ADS_Circle:
79  glEnableClientState(GL_VERTEX_ARRAY);
80  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
81  glVertexPointer(2, GL_FLOAT, 0, _circleVertices);
82  glTexCoordPointer(2, GL_FLOAT, 0, _circleTextureCoords);
83  glDrawArrays(GL_TRIANGLE_FAN, 0, CIRCLE_DRAW_SECTIONS+2);
84  break;
85 
86  case ADS_CustomList:
87  #if ANGEL_MOBILE
88  sysLog.Printf("glCallList is unsupported in OpenGL|ES.");
89  #else
90  if (_displayListIndex < 0)
91  {
92  sysLog.Printf("Invalid display list index: %i.", _displayListIndex);
93  }
94  else
95  {
96  glCallList(_displayListIndex);
97  }
98  #endif
99  break;
100  }
101 
102  if (textureReference >= 0)
103  {
104  glDisable(GL_TEXTURE_2D);
105  }
106 
107  glPopMatrix();
108  glMatrixMode(GL_PROJECTION);
109  glPopMatrix();
110  glMatrixMode(GL_MODELVIEW);
111 }
112