00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef TEDDY__GRAPHICS__VIEW__H
00026 #define TEDDY__GRAPHICS__VIEW__H
00027
00028
00029 #include "Teddy/Maths/Matrix.h"
00030 #include "Teddy/Maths/Vector2.h"
00031 #include "Teddy/Maths/Vector.h"
00032 #include "Teddy/Maths/Rect.h"
00033 #include "Teddy/MixIn/Options.h"
00034 #include "Teddy/Graphics/Color.h"
00035 #include "Teddy/Graphics/Device.h"
00036 #ifdef HAVE_LIB_PNG
00037 # include <png.h>
00038 #endif
00039
00040
00041
00042 namespace Teddy {
00043 namespace PhysicalComponents { class Layer; };
00044 namespace PhysicalComponents { class WindowManager; };
00045 };
00046 struct SDL_Surface;
00047
00048
00049 namespace Teddy {
00050 namespace Graphics {
00051
00052
00053 class Color;
00054 class Font;
00055 class Texture;
00056
00057
00065 class View {
00066 public:
00067 static const int OPT_FRAME;
00068 static const int OPT_FULLSCREEN;
00069 static const int OPT_MULTI_WINDOW;
00070 static const int OPT_SEPARATE_SPECULAR_COLOR;
00071 static const int OPT_FONT_FIX;
00072
00073 static const unsigned long CULL_FACE ;
00074 static const unsigned long BLEND ;
00075 static const unsigned long FOG ;
00076 static const unsigned long NORMALIZE ;
00077 static const unsigned long ALPHA_TEST ;
00078 static const unsigned long DEPTH_TEST ;
00079 static const unsigned long STENCIL_TEST ;
00080 static const unsigned long SCISSOR_TEST ;
00081 static const unsigned long TEXTURE_1D ;
00082 static const unsigned long TEXTURE_2D ;
00083 static const unsigned long POINT_SMOOTH ;
00084 static const unsigned long LINE_SMOOTH ;
00085 static const unsigned long POLYGON_SMOOTH;
00086 static const unsigned long POINT_OFFSET ;
00087 static const unsigned long LINE_OFFSET ;
00088 static const unsigned long POLYGON_OFFSET;
00089 static const unsigned long LIGHTING ;
00090 static const unsigned long LIGHT0 ;
00091 static const unsigned long LIGHT1 ;
00092 static const unsigned long LIGHT2 ;
00093 static const unsigned long LIGHT3 ;
00094 static const unsigned long LIGHT4 ;
00095 static const unsigned long LIGHT5 ;
00096 static const unsigned long LIGHT6 ;
00097 static const unsigned long LIGHT7 ;
00098 static const unsigned long COLOR_MATERIAL;
00099
00100 static void init();
00101 static char *feature_to_str( int a );
00102 static unsigned int getCode(unsigned int a);
00103
00104 private:
00105 static unsigned int feature_to_code[256];
00106
00107
00108 public:
00109 View( int width, int height, Teddy::MixIn::Options options );
00110
00111
00112 void reshape ( int w, int h );
00113 void display ();
00114 void displayPs ( char *filename );
00115
00116 const Teddy::Maths::TVector2<int> &getSize () const;
00117 float getRatio ();
00118 int getFrames ();
00119 float getLastFrame ();
00120 float getFps ();
00121 float getFpsTime ();
00122 float getLastTime ();
00123
00124 void setWindowManager ( Teddy::PhysicalComponents::WindowManager *wm );
00125 Teddy::Maths::Matrix getOrthoMatrix ( float left, float right, float bottom, float top, float nearval, float farval );
00126
00127 void setProjectionMatrix();
00128 void setProjectionMatrix( const Teddy::Maths::Matrix &m );
00129 void setModelViewMatrix ();
00130 void setModelViewMatrix ( const Teddy::Maths::Matrix &m );
00131 void setTextureMatrix ( const Teddy::Maths::Matrix &m );
00132 void setTexture ( Texture *t );
00133 void setCull ( unsigned long dir );
00134
00135 void beginPoints ();
00136 void beginLines ();
00137 void beginLineStrip ();
00138 void beginLineLoop ();
00139 void beginTriangles ();
00140 void beginTriangleStrip ();
00141 void beginTriangleFan ();
00142 void beginQuads ();
00143 void beginQuadStrip ();
00144 void beginPolygon ();
00145 void end ();
00146
00147 void vertex ( const Teddy::Maths::TVector<float> &v, const Teddy::Maths::TVector2<float> &t ) const;
00148 void vertex ( const Teddy::Maths::TVector2<float> &v, const Teddy::Maths::TVector2<float> &t ) const;
00149 void vertex ( const float x, const float y ) const;
00150
00151 void vertex ( const Teddy::Maths::TVector <int> &v ) const;
00152 void vertex ( const Teddy::Maths::TVector <float> &v ) const;
00153 void vertex ( const Teddy::Maths::TVector <double> &v ) const;
00154 void vertex ( const Teddy::Maths::TVector2<int> &v ) const;
00155 void vertex ( const Teddy::Maths::TVector2<float> &v ) const;
00156 void vertex ( const Teddy::Maths::TVector2<double> &v ) const;
00157 void normal ( const Teddy::Maths::TVector <int> &n ) const;
00158 void normal ( const Teddy::Maths::TVector <float> &n ) const;
00159 void normal ( const Teddy::Maths::TVector <double> &n ) const;
00160 void normal ( const Teddy::Maths::TVector2<int> &n ) const;
00161 void normal ( const Teddy::Maths::TVector2<float> &n ) const;
00162 void normal ( const Teddy::Maths::TVector2<double> &n ) const;
00163 void texture ( const Teddy::Maths::TVector <int> &t ) const;
00164 void texture ( const Teddy::Maths::TVector <float> &t ) const;
00165 void texture ( const Teddy::Maths::TVector <double> &t ) const;
00166 void texture ( const Teddy::Maths::TVector2<int> &t ) const;
00167 void texture ( const Teddy::Maths::TVector2<float> &t ) const;
00168 void texture ( const Teddy::Maths::TVector2<double> &t ) const;
00169 void color ( const float r, const float g, const float b, const float a = 1 ) const;
00170 void color ( const Color &c ) const;
00171 void begin2d ();
00172 void end2d ();
00173
00174 void printExtensions ();
00175 bool hasExtension ( const char *ext_name );
00176 char *getExtensions ();
00177 char *getVendor ();
00178 char *getRenderer ();
00179 char *getVersion ();
00180 int getMaxTextureSize ();
00181 int getMaxLights ();
00182 Teddy::Maths::TVector<int> getMaxViewportDims ();
00183
00184 void drawString ( const Teddy::Maths::TVector2<float> &pos, const char *str, Font *font );
00185 void drawRect ( const float x1, const float y1, const float x2, const float y2 );
00186 void drawFillRect ( const float x1, const float y1, const float x2, const float y2 );
00187 void drawBiColRect ( const float x1, const float y1, const float x2, const float y2, const Color &top_left, const Color &bottom_right );
00188 void blit ( const Teddy::Maths::TVector2<float> &pos, Texture *t );
00189
00190 void setClear ( bool clear );
00191 void setClearColor ( const Color &clear_color );
00192 bool getClear ();
00193 void begin3d ();
00194 void end3d ();
00195 void setState ( const int feature, const bool state );
00196 bool getState ( const int feature );
00197 void enable ( const int feature );
00198 void disable ( const int feature );
00199 void setPolygonMode ( const unsigned int polygon_mode );
00200 void setShadeModel ( const unsigned int shade_model );
00201 void setFrontFace ( const unsigned int front_face );
00202 void setBlendFunc ( const unsigned int sfactor, const unsigned int dfactor );
00203 void setClearDepth ( const float depth );
00204 void setFogStart ( const float start );
00205 void setFogEnd ( const float end );
00206 void setFogMode ( const unsigned int mode );
00207 void setFogColor ( float *color );
00208
00209 int getScreenWidth();
00210 int getScreenHeight();
00211
00212 bool pngScreenshot ( char *filename );
00213 SDL_Surface *getSurface ();
00214 Teddy::MixIn::Options &getOptions (){ return options; }
00215
00216 static void check ();
00217 #if defined( HAVE_LIB_PNG )
00218 static void pngUserWriteData( png_structp png_ptr, png_bytep data, png_size_t length );
00219 static void pngUserFlushData( png_structp png_ptr );
00220 #endif
00221
00222 protected:
00223 Teddy::MixIn::Options options;
00224 SDL_Surface *sdl_surface;
00225 Teddy::PhysicalComponents::WindowManager *window_manager;
00226 Texture *current_texture;
00227 Teddy::Maths::TVector2<int> size;
00228 int current_element;
00229 int current_matrix_mode;
00230 float ratio;
00231 bool clear;
00232 Color clear_color;
00233 unsigned int gl_blend_source_factor;
00234 unsigned int gl_blend_destination_factor;
00235 unsigned int gl_fog_mode;
00236 unsigned int gl_polygon_mode;
00237 unsigned int gl_shade_model;
00238 float gl_fog_start;
00239 float gl_fog_end;
00240 float gl_fog_color[4];
00241 float gl_clear_depth;
00242 bool gl_feature[256];
00243 int frames;
00244 unsigned long last_frame;
00245 unsigned long last_time;
00246 unsigned long last_fps;
00247 float fps;
00248 int screen_width;
00249 int screen_height;
00250
00251 protected:
00252 static View *active;
00253 static FILE *fp;
00254
00255 static void displayOne ();
00256 static void reshapeOne ( int w, int h );
00257 };
00258
00259
00260 };
00261 };
00262
00263
00264 #endif // TEDDY__GRAPHICS__VIEW__H
00265