1 //==============================================================================
2 // This program is free software; you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation; either version 2 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU Library General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 //==============================================================================
16 
17 //==============================================================================
18 // File: cDisplayManager.cpp
19 // Project: Shooting Star
20 // Author:
21 // Copyrights (c) 2003 2ndPoint ry (www.2ndpoint.fi)
22 //------------------------------------------------------------------------------
23 // Revision history
24 //==============================================================================
25 
26 //==============================================================================
27 // Includes
28 #include "cDisplayManager.hpp"
29 #include <stdlib.h>
30 //------------------------------------------------------------------------------
31 // Namespaces
32 using namespace ShootingStar;
33 //==============================================================================
34 
35 //==============================================================================
36 //! Constructor
37 //------------------------------------------------------------------------------
cDisplayManager(void)38 cDisplayManager::cDisplayManager (void)
39 {
40 };
41 //==============================================================================
42 
43 //==============================================================================
44 //! Destructor
45 //------------------------------------------------------------------------------
~cDisplayManager(void)46 cDisplayManager::~cDisplayManager (void)
47 {
48 };
49 //==============================================================================
50 
51 //==============================================================================
52 //! Return singleton
53 //------------------------------------------------------------------------------
54 cDisplayManager &
GetInstance(void)55 cDisplayManager::GetInstance (void)
56 {
57 	static cDisplayManager singleton ;
58 	return singleton;
59 }
60 //==============================================================================
61 
62 
63 //==============================================================================
64 //! Set videomode
65 //------------------------------------------------------------------------------
SetVideoMode(int width,int height,int bpp,Uint32 flags)66 void cDisplayManager::SetVideoMode( int width, int height, int bpp, Uint32 flags ){
67 
68 	dbgInfo () << "Trying to set " << width << 'x' << height << 'x' << bpp << " video mode\n";
69 	mpScreen = SDL_SetVideoMode( width, height, bpp, flags );
70 	if ( mpScreen == NULL )
71 	{
72 		dbgError () << "Unable to set video mode: " << SDL_GetError () << endl;
73 		throw runtime_error ("Initialization failed");
74 	}
75 	dbgInfo () << "Got " << mpScreen->w << 'x' << mpScreen->h << 'x' << (int) mpScreen->format->BitsPerPixel << " video mode\n";
76 
77 }
78 //==============================================================================
79 //==============================================================================
80 //! Set viewport
81 //------------------------------------------------------------------------------
SetViewport(GLint x,GLint y,GLsizei width,GLsizei height)82 void cDisplayManager::SetViewport(  GLint x, GLint y, GLsizei width, GLsizei height ){
83 
84 	glViewport (x, y, width, height );
85 
86 }
87 //==============================================================================
88 //==============================================================================
89 //! Set gluortho
90 //------------------------------------------------------------------------------
SetOrtho(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top)91 void cDisplayManager::SetOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top ) {
92 
93 	gluOrtho2D (left, right, bottom , top);
94 
95 }
96 //==============================================================================
97 //==============================================================================
98 void
BeginFrame(bool clear)99 cDisplayManager::BeginFrame (bool clear)
100 {
101 	if ( clear )
102 	{
103 		// Clear screen and depth buffer
104 		glClear (GL_COLOR_BUFFER_BIT);
105 	}
106 
107 	// Select and reset the modelview matrix
108 	glMatrixMode (GL_MODELVIEW);
109 	glLoadIdentity();
110 }
111 //==============================================================================
112 
113 //==============================================================================
114 void
EndFrame(void)115 cDisplayManager::EndFrame (void)
116 {
117 	// Flip
118 	SDL_GL_SwapBuffers ();
119 }
120 //==============================================================================
121 
122 //==============================================================================
123 Uint16
GetViewportWidth(void)124 cDisplayManager::GetViewportWidth (void)
125 {
126 	GLint viewport[4];
127 	glGetIntegerv( GL_VIEWPORT, viewport );
128 	return viewport[2];
129 }
130 //==============================================================================
131 //==============================================================================
132 Uint16
GetViewportHeight(void)133 cDisplayManager::GetViewportHeight (void)
134 {
135 	GLint viewport[4];
136 	glGetIntegerv( GL_VIEWPORT, viewport );
137 	return viewport[3];
138 }
139 //==============================================================================
140 //==============================================================================
141 Uint16
GetOrthoWidth(void)142 cDisplayManager::GetOrthoWidth (void)   // dunno how to get ortho's size so get screen size =)
143 {
144 	return mpScreen->w;
145 }
146 //==============================================================================
147 //==============================================================================
148 Uint16
GetOrthoHeight(void)149 cDisplayManager::GetOrthoHeight (void)
150 {
151 	return mpScreen->h;
152 }
153 //==============================================================================
154 
155 
156 //==============================================================================
157 // EOF
158 //==============================================================================
159