00001
00012 #ifndef GLRENDERSYSTEM_H
00013 #define GLRENDERSYSTEM_H
00014
00015 #include <boost/shared_ptr.hpp>
00016 #include "GLHeaders.h"
00017 #include "RenderSystem.h"
00018 #include "util/DrawStuff.h"
00019 #include "util/Error.h"
00020
00021
00022 namespace green
00023 {
00028 class GLRenderSystem : public RenderSystem
00029 {
00030 public:
00037 void StartFrame()
00038 {
00039 glClearColor(GLclampf(mClearColor.r),
00040 GLclampf(mClearColor.g),
00041 GLclampf(mClearColor.b),
00042 GLclampf(mClearColor.a));
00043 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00044 glMatrixMode(GL_MODELVIEW);
00045 glLoadIdentity();
00046 }
00047
00054 void FinishFrame()
00055 {
00056 glFlush();
00057 glFinish();
00058 }
00059
00066 void DrawObject(Graphic object, double x, double y, double rot)
00067 {
00068 glPushMatrix();
00069 glLoadIdentity();
00070 glTranslated(x, y, 0.0);
00071 glRotated(rot, 0.0, 0.0, 1.0);
00072
00073
00074 switch(object)
00075 {
00076 case SHIP:
00077 DrawShip();
00078 break;
00079 case BULLET:
00080 DrawBullet();
00081 break;
00082 case ASTEROID:
00083 DrawAsteroid();
00084 break;
00085 default:
00086 THROW_ERROR("unknown Graphic type");
00087 break;
00088 }
00089 glPopMatrix();
00090 }
00091
00099 inline
00100 void Reshape(int width, int height) {
00101 glViewport(0, 0, width, height);
00102 glMatrixMode(GL_PROJECTION);
00103 glLoadIdentity();
00104
00105
00106 GLfloat halfWidth((GLfloat) (width / 2));
00107 GLfloat halfHeight((GLfloat) (height / 2));
00108
00109 gluOrtho2D((GLfloat) -halfWidth, halfWidth, -halfHeight, halfHeight);
00110 glMatrixMode(GL_MODELVIEW);
00111 }
00112 };
00113 typedef boost::shared_ptr<GLRenderSystem> GLRenderSystemPtr;
00114 }
00115
00116 #endif