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
00026
00027
00028 #include "aa_config.h"
00029
00030 #ifndef DEDICATED
00031
00032 #define DONTDOIT
00033 #include "rRender.h"
00034 #include "rGL.h"
00035 #include "tMemManager.h"
00036 #include "tError.h"
00037
00038 class glRenderer: public rRenderer{
00039 GLenum lastPrimitive;
00040 bool forceglEnd;
00041
00042 GLenum lastMatrix;
00043
00044 void BeginPrimitive(GLenum p, bool forceEnd = false){
00045
00046
00047
00048 if (lastPrimitive != p && lastPrimitive != GL_FALSE)
00049 {
00050 glEnd();
00051 sr_CheckGLError();
00052 }
00053
00054 if ( lastPrimitive != p )
00055 {
00056 sr_CheckGLError();
00057 glBegin(p);
00058 }
00059
00060 lastPrimitive = p;
00061
00062 forceglEnd = forceEnd;
00063 }
00064
00065 void MatrixMode(GLenum mm){
00066
00067 {
00068 glMatrixMode(mm);
00069 lastMatrix = mm;
00070 }
00071 }
00072
00073 public:
00074 glRenderer():lastPrimitive(GL_FALSE), forceglEnd(false), lastMatrix(GL_FALSE){
00075 ChangeFlags(0xffffffff,0);
00076 };
00077
00078 virtual ~glRenderer(){};
00079
00080 virtual void Vertex(REAL x, REAL y){
00081 glVertex2f(x,y);
00082 };
00083
00084 virtual void Vertex(REAL x, REAL y, REAL z){
00085 glVertex3f(x,y,z);
00086 }
00087
00088 virtual void Vertex3(REAL *x){
00089 glVertex3fv(x);
00090 }
00091
00092 virtual void Vertex(REAL x, REAL y, REAL z, REAL w){
00093 glVertex4f(x,y,z,w);
00094 }
00095
00096 virtual void TexCoord(REAL u, REAL v){
00097 glTexCoord2f(u,v);
00098 }
00099
00100 virtual void TexCoord(REAL u, REAL v, REAL w){
00101 glTexCoord3f(u,v,w);
00102 }
00103
00104 virtual void TexCoord(REAL u, REAL v, REAL w, REAL t){
00105 glTexCoord4f(u,v,w,t);
00106 };
00107
00108 virtual void TexVertex(REAL x, REAL y, REAL z,
00109 REAL u, REAL v){
00110 glTexCoord2f(u,v);
00111 glVertex3f(x,y,z);
00112 }
00113
00114
00115 virtual void Color(REAL r, REAL g, REAL b){
00116 glColor3f(r,g,b);
00117 };
00118
00119 virtual void Color(REAL r, REAL g, REAL b,REAL a){
00120 glColor4f(r,g,b,a);
00121 };
00122
00123
00124 virtual void End(bool force=true){
00125
00126
00127
00128 if ((forceglEnd || force ) && lastPrimitive!=GL_FALSE)
00129 {
00130 forceglEnd = false;
00131 glEnd();
00132 sr_CheckGLError();
00133 lastPrimitive = GL_FALSE;
00134 }
00135 }
00136
00137 virtual void BeginLines(){
00138 BeginPrimitive(GL_LINES);
00139 };
00140
00141 virtual void BeginTriangles(){
00142 BeginPrimitive(GL_TRIANGLES);
00143 }
00144
00145 virtual void BeginQuads(){
00146 BeginPrimitive(GL_QUADS);
00147 }
00148
00149 virtual void BeginLineStrip(){
00150 BeginPrimitive(GL_LINE_STRIP, true);
00151 };
00152
00153 virtual void BeginLineLoop(){
00154 BeginPrimitive(GL_LINE_LOOP, true);
00155 };
00156
00157 virtual void BeginTriangleStrip(){
00158 BeginPrimitive(GL_TRIANGLE_STRIP, true);
00159 };
00160
00161 virtual void BeginQuadStrip(){
00162 BeginPrimitive(GL_QUAD_STRIP, true);
00163 };
00164
00165 virtual void BeginTriangleFan(){
00166 BeginPrimitive(GL_TRIANGLE_FAN, true);
00167 };
00168
00169 virtual void Line(REAL x1, REAL y1, REAL z1,
00170 REAL x2, REAL y2, REAL z2){
00171 BeginPrimitive(GL_LINES);
00172 glVertex3f(x1,y1,z1);
00173 glVertex3f(x2,y2,z2);
00174 End();
00175 }
00176
00177
00178
00179
00180 virtual void ProjMatrix(){
00181 End(true);
00182 MatrixMode(GL_PROJECTION);
00183 };
00184
00185 virtual void ModelMatrix(){
00186 End(true);
00187 MatrixMode(GL_MODELVIEW);
00188 };
00189
00190 virtual void TexMatrix(){
00191 End(true);
00192 MatrixMode(GL_TEXTURE);
00193 };
00194
00195 virtual void PushMatrix(){
00196 glPushMatrix();
00197 };
00198
00199 virtual void PopMatrix(){
00200 End(true);
00201 glPopMatrix();
00202 };
00203
00204 virtual void MultMatrix(REAL mdata[4][4]){
00205 End(true);
00206 tASSERT(sizeof(REAL) == sizeof(GLfloat));
00207 REAL * mdat=&mdata[0][0];
00208 glMultMatrixf(reinterpret_cast<GLfloat *>(mdat));
00209 };
00210
00211 virtual void IdentityMatrix(){
00212 End(true);
00213 glLoadIdentity();
00214 };
00215
00216 virtual void ScaleMatrix(REAL f){
00217 End(true);
00218 glScalef(f,f,f);
00219 };
00220
00221 virtual void ScaleMatrix(REAL f1, REAL f2, REAL f3){
00222 End(true);
00223 glScalef(f1,f2,f2);
00224 };
00225
00226 virtual void TranslateMatrix(REAL x1, REAL x2, REAL x3){
00227 End(true);
00228 glTranslatef(x1,x2,x3);
00229 }
00230
00231
00232
00233 virtual void ReallySetFlag(flag f,bool c){
00234 GLenum fl = GL_DEPTH_TEST;
00235 switch (f)
00236 {
00237 case ALPHA_BLEND:
00238 fl = GL_BLEND;
00239 break;
00240 case DEPTH_TEST:
00241 fl = GL_DEPTH_TEST;
00242 break;
00243 default:
00244 break;
00245 }
00246
00247 if (c)
00248 glEnable(fl);
00249 else
00250 glDisable(fl);
00251 };
00252
00253 };
00254
00255 void sr_glRendererInit(){
00256 tNEW(glRenderer);
00257 }
00258
00259 #endif