00001
00002 #ifndef __H_GRAPHICS_H_
00003 #define __H_GRAPHICS_H_
00004
00005 namespace std {}
00006 using namespace std;
00007
00008 #include "H_Standard.h"
00009
00010 #include <map>
00011 #include <string>
00012
00013 #include "H_Main.h"
00014 #include "H_Geometry.h"
00015 #include "H_Texture.h"
00016
00017
00018 #define FONT_WIDTH 8
00019 #define FONT_HEIGHT 13
00020
00021
00022 #define FIELD_OF_VIEW 90.0f
00023 #define NEAR_PLANE 1.0f //near clipping plane at 1meter
00024 #define FAR_PLANE 500.0f //far plane at 500m
00025
00026
00027 #define HGL_SHADOWS_DEFAULT 2
00028 #define HGL_TEXTURE_MODE_DEFAULT Hgl::LINEAR
00029 #define HGL_VERTEX_ARRAYS_DEFAULT true
00030 #define HGL_EXT_COMPILED_VERTEX_ARRAYS_DEFAULT true
00031 #define HGL_FINISH_DEFAULT false
00032
00033
00034 #define HGL_DELETE_LIST(x) {if ((x)!=0) {glDeleteLists((x),1); (x) = 0;}}
00035 #define HGL_NEW_LIST(x) {HGL_DELETE_LIST(x); (x) = glGenLists(1); glNewList((x), GL_COMPILE);}
00036
00037
00038 #define HGL_DELETE_TEXTURE(x) {if ((x)!=0) {glDeleteTextures(1,&(x)); (x) = 0;}}
00039
00040
00041 typedef Point<3,GLfloat> Color;
00042
00043 extern const Color Black;
00044 extern const Color White;
00045 extern const Color Grey;
00046
00047
00048
00049
00050 class Hgl
00051 {
00052 public:
00053 Hgl(HWindow *w);
00054 void MakeCurrent();
00055 static void SwapBuffers();
00056 static Hgl &GetCurrent();
00057 static map<string,Texture::Reference> &GetLoadedTextures();
00058 public:
00059 enum Enum {
00060 LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
00061 LINEAR = GL_LINEAR,
00062 NEAREST = GL_NEAREST,
00063 NONE = GL_NONE,
00064 INVALID_ENUM = GL_INVALID_ENUM,
00065 SHADOW
00066 };
00067 public:
00068
00069 static inline void Normal(const Point<3,GLfloat> &APoint)
00070 {glNormal3fv((GLfloat*)&APoint);}
00071 static inline void Vertex(const Point<3,GLfloat> &APoint)
00072 {glVertex3fv((GLfloat*)&APoint);}
00073 static inline void Vertex(const Point<2,GLfloat> &APoint)
00074 {glVertex2fv((GLfloat*)&APoint);}
00075 static inline void TexCoord(const Point<2,GLfloat> &APoint)
00076 {glTexCoord2fv((GLfloat*)&APoint);}
00077 static inline void SetColor(const Color &AColor)
00078 {glColor3f(AColor.x(), AColor.y(), AColor.z());}
00079 static void ClearColor(const Color &AColor);
00080 static void Translate(const Point<3,GLfloat> &Location);
00081 static void Rotate(REAL teta, const Point<3,GLfloat> &Axe);
00082 static inline void Scale(REAL scale)
00083 {glScalef(scale,scale,scale);}
00084 static void LockArrays(int first, int count);
00085 static void UnlockArrays();
00086 static inline void Begin(int type)
00087 {glBegin((GLenum)type);}
00088 static inline void End()
00089 {glEnd();}
00090 static void Finish();
00091 static ostream &PrintVersion(ostream &out);
00092 static ostream &PrintExtentions(ostream &out);
00093 static ostream &PrintDebug(ostream &out);
00094 static void ResizeWindow(HRect &ClientRect);
00095 static HRect GetViewPort();
00096 static void WriteText(const char* AText, const Point<2,GLfloat> &APosition);
00097 static void WriteText(const char* AText, const Point<3,GLfloat> &APosition);
00098 static void LookFrom(const Ref & ARef);
00099
00100
00101
00102
00103 static void Relocate(const Ref &Position);
00104 static void SetLightSource(Point<3,GLfloat> LightDirection);
00105 static void Viewport(const HRect &ClientRect);
00106 static void ShadowTransform(const Point<3,GLfloat> &ALightPos, Point<3,GLfloat> APlane[3]);
00107 static void ShadowTransform(const Point<3,GLfloat> &ALightPos, const Contact &ShadowContact);
00108 static void PurgeError();
00109 static void ThrowError();
00110
00111 static void Enable(Enum variable);
00112 static void Disable(Enum variable);
00113 static bool IsEnabled(Enum variable);
00114
00115
00116 static void SetShadows(int value);
00117 static int GetShadows();
00118
00119 static void SetTextureMode(Enum value);
00120 static Enum GetTextureMode();
00121
00122 static void SetVertexArrays(bool value);
00123 static bool GetVertexArrays();
00124
00125 static void SetExtCompiledVertexArrays(bool value);
00126 static bool GetExtCompiledVertexArrays();
00127
00128 static void SetFinish(bool value);
00129 static bool GetFinish();
00130 private:
00131 static bool &GetCapEnable(Enum variable);
00132 private:
00133
00134 HWindow *m_window;
00135
00136 PFNGLLOCKARRAYSEXTPROC glLockArrays;
00137 PFNGLUNLOCKARRAYSEXTPROC glUnlockArrays;
00138
00139 static Hgl *curr;
00140 map<string,Texture::Reference> LoadedTextures;
00141 GLuint fontOffset;
00142 HRect MyViewPort;
00143 bool Shadow;
00144 Command GLExtentions;
00145
00146 int gl_shadows;
00147 Enum gl_texturemode;
00148 bool gl_vertex_arrays;
00149 bool gl_ext_compiled_vertex_array;
00150 bool gl_finish;
00151 };
00152
00153 const char* ToStr(Hgl::Enum val);
00154 Hgl::Enum ToHglEnum(const char* str);
00155
00156 istream &operator>> (istream &in, Hgl::Enum &A);
00157 ostream &operator<< (ostream &out, const Hgl::Enum &A);
00158
00159 #endif //__H_GRAPHICS_H_