00001 #ifndef GSGL_FRAMEWORK_SCREEN_H 00002 #define GSGL_FRAMEWORK_SCREEN_H 00003 00004 // 00005 // $Id: display.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "platform/platform.hpp" 00038 #include "platform/font.hpp" 00039 #include "data/config.hpp" 00040 #include "math/math.hpp" 00041 #include "math/transform.hpp" 00042 00043 // forward declarations 00044 struct SDL_Surface; 00045 00046 namespace gsgl 00047 { 00048 00049 namespace platform 00050 { 00051 00052 // 00053 class texture; 00054 00055 00056 /// This class represents a screen on which to draw. 00057 class PLATFORM_API display 00058 { 00059 struct SDL_Surface *surface; 00060 bool is_console; 00061 00062 math::transform text_draw_modelview; 00063 math::transform text_draw_projection; 00064 math::transform text_draw_pm; 00065 int text_draw_viewport[4]; 00066 00067 public: 00068 display(const int & width, const int & height, bool is_console = false); 00069 virtual ~display(); 00070 00071 static data::config_variable<int> DISPLAY_WIDTH; 00072 static data::config_variable<int> DISPLAY_HEIGHT; 00073 00074 int get_width() const; 00075 int get_height() const; 00076 gsgl::real_t get_aspect_ratio() const; 00077 00078 /// Draws a possibly textured rectangle (a suitable projection must already be set up). 00079 /// Operates in the current OpenGL context, not in any particular display. 00080 static void draw_rectangle(float x1, float y1, float x2, float y2, 00081 float s1 = 0, float t1 = 0, float s2 = 1, float t2 = 1); 00082 00083 /// Records the 3D modelview, projection and viewport information for subsequent calls to draw_3d_text(). 00084 void record_3d_text_info(); 00085 00086 /// Sets up an orthogonal view frustum for drawing text. 00087 void draw_text_start(); 00088 00089 /// Draws text at the given screen coordinates. 00090 void draw_2d_text(const gsgl::real_t x, const gsgl::real_t y, font *f, const gsgl::string & str); 00091 00092 /// Draws text at the given world coordinates. 00093 void draw_3d_text(const math::vector & p, font *f, const gsgl::string & str, const gsgl::real_t x_offset = 0, const gsgl::real_t y_offset = 0); 00094 00095 /// Tears down the orthogonal view frustum for drawing text. 00096 void draw_text_stop(); 00097 00098 private: 00099 void center_console_window(const int & width, const int & height); 00100 }; // class display 00101 00102 } // namespace platform 00103 00104 } // namespace gsgl 00105 00106 #endif