Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_BlenderGL.cpp

Go to the documentation of this file.
00001 extern "C" struct Global G;
00002 
00003 extern "C" void myswapbuffers();
00004 extern "C" struct ScrArea* curarea;
00005 extern "C" void areawinset(short win);
00006 extern "C" void drawcamera(struct Object* ob);
00007 extern "C" void error(char* err);
00008 extern "C" void waitcursor(int);
00009 extern "C" void allqueue(unsigned short,short);
00010 extern "C" void screen_swapbuffers();
00011 extern "C" void mymultmatrix(float mat[][4]);
00012 extern "C" unsigned int rgb_to_cpack(float r,float g,float b);
00013 extern "C" void drawname(struct Object* ob);
00014 extern "C" void drawaxes(float size);
00015 extern "C" int set_tpage(struct TFace* tface);
00016 #ifdef WIN32
00017 #include <windows.h>
00018 extern "C" void APIENTRY glutSwapBuffers();
00019 #else 
00020 extern "C" void glutSwapBuffers();
00021 #endif //WIN32
00022 
00023 
00024 extern "C" void drawDispList(Object *ob, int dt);
00025 extern "C" void setlinestyle(int);
00026 extern "C" void drawcircball(float* cent,float rad,float tmat[][4]);
00027 extern "C" void mygetmatrix(float mat[][4]);
00028 extern "C" void set_dtime(int dtime);
00029 extern "C" int set_gl_light_bylayer(int objectlayer);
00030 extern "C" void setviewmatrixview3d();
00031 extern "C" void setwinmatrixview3d(struct BlenderRect* rect);
00032 extern "C" void build_sectorlist(struct Object* cam);
00033 extern "C" void spack(unsigned int ucol);
00034 extern "C" void matrixGlyph(struct ImBuf * ibuf, unsigned short unicode,
00035                 float *centerx, float *centery,
00036                 float *sizex,   float *sizey,
00037                 float *transx,  float *transy,
00038                 float *movex,   float *movey,
00039                 float *advance);
00040 extern "C" void fmprstr(char* str);
00041 extern "C" void persp(int a);
00042 extern "C" void fmsetfont(void *type);
00043 #include "KX_BlenderGL.h"
00044 
00045 #include "blender.h"
00046 #include "screen.h"
00047 #include "sector.h" // only used for the definition of "Life" :(
00048 
00049 #include <GL/gl.h>
00050 
00051 //#include "game.h"
00052 
00053 extern "C" void init_gl_stuff();
00054 extern "C" void default_gl_light();
00055 extern "C" void reset_slowparents();
00056 extern "C" void warp_pointer(int x,int y);
00057 
00058 
00059 
00060 void BL_warp_pointer(int x,int y)

00061 {
00062         warp_pointer(x,y);
00063         
00064 }
00065 
00066 /*
00067  * BL_SaveState saves the OpenGL state that blender needs, used on startup of the gameengine

00068  */
00069 int BL_SaveState()

00070 {
00071         glPushAttrib(GL_ALL_ATTRIB_BITS);
00072 
00073         init_gl_stuff();
00074         
00075 
00076         if(G.scene->camera==0 || G.scene->camera->type!=OB_CAMERA) {
00077                 error("no (correct) camera");
00078                 return FALSE;
00079         }
00080         if(G.vd==0) return FALSE;       
00081 
00082         G.f |= G_SIMULATION;
00083         G.simulf= 0;
00084                 
00085         waitcursor(1);
00086 
00087         set_dtime(1);//4        
00088 
00089         return TRUE;
00090 
00091 }
00092 
00093 /*
00094  *      Restore state restores the OpenGL state on exit of the gameengine

00095  */
00096 void BL_RestoreState()

00097 {
00098         curarea->win_swap = 0;
00099         curarea->head_swap=0;
00100         G.simulf |= G_QUIT;
00101         G.f &= ~G_SIMULATION;
00102         allqueue(REDRAWVIEW3D, 0);
00103         allqueue(REDRAWBUTSALL, 0);
00104         reset_slowparents();
00105         waitcursor(0);
00106         set_dtime(2);   /* restore */
00107         G.qual= 0;
00108         glPopAttrib();
00109 }
00110 
00111 
00112 void BL_SwapBuffers()

00113 {
00114         // quake 3 team arena doesn't have glFlush before swapbuffers, unreal tournament does
00115         //glFlush();
00116         curarea->win_swap = WIN_BACK_OK;
00117         glutSwapBuffers();
00118         //screen_swapbuffers();
00119 
00120         //myswapbuffers();
00121         
00122         
00123 }
00124 
00125 
00126 extern "C" void update_realtime_textures();
00127 
00128 
00129 void BL_FixedUpdate()

00130 {
00131         update_realtime_textures();
00132 }
00133 
00134 
00135 extern "C" void init_sectors();
00136 extern "C" void init_lifes();
00137 extern "C" void init_devs();
00138 
00139 void    BL_InitSectorVisibility()

00140 {
00141         // check if these remains of old blender prototype gameengine are still necessary
00142         //init_sectors();
00143         init_lifes();
00144         //init_devs();
00145 }
00146 
00147 extern "C" void end_sectors();
00148 extern "C" void end_lifes(int restore);
00149 
00150 void    BL_ExitSectorVisibility(int restore)

00151 {
00152         end_sectors();
00153         end_lifes(restore);
00154         
00155 }
00156 extern "C" void draw_gamedebug_info();
00157 
00158 
00159 void BL_EndFrame()

00160 {
00161         areawinset(curarea->win);
00162         default_gl_light();
00163         set_tpage(NULL);
00164 }
00165 
00166 // Blender viewport issues
00167 void    BL_BeginFrame()

00168 {
00169         // set the area here, else rendering could be done in the wrong viewport/area of the screen
00170         
00171         default_gl_light();
00172         // set some internal flag for the zbuffer
00173         if (G.vd->drawtype >= OB_SOLID)
00174                 G.zbuf = TRUE;
00175 }
00176 
00177 
00178 #define cpack(x)        glColor3ub( ((x)&0xFF), (((x)>>8)&0xFF), (((x)>>16)&0xFF) )
00179 
00180 void BL_DisplayCamera()

00181 {
00182 /* extern: camera tekenen */
00183         if(G.vd->persp!=2) {
00184                         
00185                 Object* ob= G.scene->camera;
00186                 if(ob && (ob->lay & G.vd->lay)) {
00187                         cpack(0x0);
00188                         multmatrix(ob->obmat);
00189                         drawcamera(ob);
00190                 }
00191         }
00192 }
00193 
00194 
00195                 
00200 void    BL_DoDebugColors(Object* ob)

00201 {
00202                 Life* lf = ob->life;
00203                 Material* ma;
00204                 
00205                 // default color is black (0)
00206                 int col= 0;
00207                 if (lf)
00208                 {
00209                         if( ma=lf->contact) 
00210                                 col= rgb_to_cpack(ma->r, ma->g, ma->b);
00211                         if( lf->flag1 & LF_DRAWNEAR) 
00212                                 col= (0xF0A020);
00213                         if(lf->collision) 
00214                                 col = 0xFFFFFF;
00215                         if(lf->dflag & LF_NO_DAMAGE) 
00216                                 col = 0x00FF00;
00217                 }
00218                 
00219                 cpack(col);
00220                 //drawlife(ob, MIN2(ob->dt, G.vd->drawtype), col);
00221 }
00222 
00223 extern "C" int Mat4Invert(float inverse[][4], float mat[][4]);
00224 
00225 void BL_DisplaySymbolicShapes(Object* ob,int dt)

00226 {
00227         return;
00228         cpack(0xffffffff);
00229 
00230         glMultMatrixf((float*) ob->obmat);
00231         
00232         glPushMatrix();
00233 
00234         if(dt<OB_SHADED) {
00235                 if( ob->gameflag & OB_DYNAMIC) {
00236                         float resultmatrix[4][4];
00237                         float imat[4][4], vec[3];
00238                         glGetFloatv(GL_MODELVIEW_MATRIX, (float*) resultmatrix);
00239                         vec[0]= vec[1]= vec[2]= 0.0;
00240                         Mat4Invert(imat, resultmatrix);
00241                         setlinestyle(2);
00242                         drawcircball(vec, ob->inertia, imat);
00243                         setlinestyle(0);
00244                 }
00245         }
00246         glPopMatrix();
00247         if(ob->dtx & OB_DRAWNAME) 
00248                 drawname(ob);
00249 
00250         BL_DoDebugColors(ob);
00251         
00252         Life* lf = ob->life;
00253         if (lf)
00254         {
00255                 if((ob->dtx & OB_AXIS) || (ob->type != OB_MESH))
00256                         drawaxes(lf->axsize);   
00257         }
00258 
00259 
00260 }
00261 
00262 void    BL_DrawShadow(struct Object* blenderobject,int drawingmode,bool wireframe)

00263 {
00264         return;
00265         if (drawingmode & TF_SHADOW)
00266         {
00267                 Life* lf = blenderobject->life;
00268                 if(lf) {
00269                         // 'project' shadow on the ground by translating it
00270                         glTranslatef(lf->floorloc[0],  lf->floorloc[1],  lf->floorloc[2]);
00271                         
00272                         if (wireframe)
00273                         {
00274                                 float vec[3];
00275                                 // draw stippled thing on this place
00276                                 glEnable(GL_POLYGON_STIPPLE);
00277                                 
00278                                 //loadmatrix(G.vd->viewmat);
00279                                 //glTranslatef(blenderobject->obmat[3][0],  blenderobject->obmat[3][1],  blenderobject->obmat[3][2]);
00280                                 
00281                                 /* floorloc is t.o.v. oldloc!!! */
00282                                 vec[0]= 0.0;
00283                                 vec[1]= 0.0;
00284                                 vec[2]= 0.0;
00285                                 vec[2]+= 0.2*lf->axsize;
00286 
00287                                 glBegin(GL_POLYGON);
00288                                 vec[0]-= 0.4*lf->axsize;
00289                                 vec[1]-= 0.4*lf->axsize;
00290                                 glVertex3fv(vec);
00291                                 vec[0]+= 0.8*lf->axsize;
00292                                 glVertex3fv(vec);
00293                                 vec[1]+= 0.8*lf->axsize;
00294                                 glVertex3fv(vec);
00295                                 vec[0]-= 0.8*lf->axsize;
00296                                 glVertex3fv(vec);
00297                                 glEnd();
00298                                 
00299                                 glDisable(GL_POLYGON_STIPPLE);
00300 
00301                                 //?? ask Ton
00302                                 glTranslatef(-lf->floorloc[0],  -lf->floorloc[1],  -lf->floorloc[2]);
00303                                 
00304                         }
00305                 }
00306         }
00307 }
00308 
00309 extern "C" void draw_bounding_volume(Object* ob);
00310 
00311 void    BL_DisplayBoundingBox(struct Object* ob)

00312 {
00313         return;
00314         draw_bounding_volume(ob);
00315 }
00316 
00317 
00318 
00319 void    BL_DisplaySolid(struct Object* blenderobject,int drawingmode)

00320 {
00321         return;
00322         drawDispList(blenderobject, drawingmode);
00323 }
00324 
00325 extern "C" void drawview3d_simul(int);
00326 
00327 void    BL_RenderScene()

00328 {
00329         //drawview3d_simul(0);
00330         //screen_swapbuffers();
00331 }
00332 
00333 
00334 
00335 
00336 int BL_getlayer(struct Object* ob) 

00337 {
00338         if (ob)
00339                 return ob->lay;
00340         return -1;
00341 }
00342 int BL_set_gl_light(int layer,float* viewmat,int dummy)

00343 {
00344         
00345         memcpy(G.vd->viewmat,viewmat,16*sizeof(float));
00346         return set_gl_light_bylayer(layer);
00347 }
00348 
00349 void    BL_setviewmatrixview3d()

00350 {
00351         setviewmatrixview3d();
00352 }
00353 
00354 float BL_GetViewDistance(struct Global* glob)

00355 {
00356 
00357         float viewdist = glob->vd->clipend;
00358         
00359         if (glob->vd->persp==2)
00360         {
00361                 if (glob->vd->camera->type == OB_CAMERA)
00362                 {
00363                         Camera* cam = (Camera*) glob->vd->camera->data;
00364                         viewdist = cam->clipend;
00365                 }
00366                 
00367         }
00368         return viewdist ;
00369 }
00370 
00371 
00372 float*  BL_GetViewMatrix(struct Global* glob)

00373 {
00374         return  glob->vd->viewmat[0];
00375 }
00376 
00377 Object* BL_GetCameraObject(struct Global* glob)

00378 {
00379         return glob->vd->camera;
00380 }
00381 
00382 
00383 const BL_Mat4x4*        BL_GetProjectionMatrix(struct ScrArea* area)

00384 {
00385         return ((const BL_Mat4x4*) &area->winmat);
00386 }
00387 
00388 
00389 
00390 bool BL_ExternalCameraPerspective()

00391 {
00392         return !(G.vd->persp>=2);
00393 }
00394 
00395 
00396 BL_BlenderWorldInfo     BL_GetBlenderWorldInfo(struct Global* glob)

00397 {
00398         BL_BlenderWorldInfo     info;
00399 
00400         info.hasworld = (glob->scene->world != NULL);
00401         info.gravity = -9.8;
00402         if (info.hasworld)
00403         {
00404                 info.backcolor_red = glob->scene->world->horr;
00405                 info.backcolor_green = glob->scene->world->horg;
00406                 info.backcolor_blue = glob->scene->world->horb;
00407 
00408                 info.hasmist = glob->scene->world->mode & WO_MIST;
00409                 if (info.hasmist)
00410                 {
00411                         info.backcolor_miststart = glob->scene->world->miststa;
00412                         info.backcolor_mistdistance = glob->scene->world->mistdist;
00413                         info.backcolor_mistcolor_red = glob->scene->world->horr;
00414                         info.backcolor_mistcolor_green = glob->scene->world->horg;
00415                         info.backcolor_mistcolor_blue = glob->scene->world->horb;
00416 
00417                 }
00418 
00419                 info.gravity = -glob->scene->world->gravity;
00420         }
00421         return info;
00422 }
00423         
00424         
00425 int     BL_GetDrawType(struct Global* glob)

00426 {
00427         return glob->vd->drawtype;
00428 }
00429 
00430 void BL_BuildSectorList() {
00431         build_sectorlist(G.scene->camera);
00432 }
00433 
00434 
00435 void BL_RenderText(int mode,const char* textstr,int textlen,struct TFace* tface,
00436                                    float v1[3],float v2[3],float v3[3],float v4[3])

00437 {
00438         Image* ima;
00439 
00440         if(mode & TF_BMFONT) {
00441                         //char string[MAX_PROPSTRING];
00442                         float ofsu, ofsv;
00443 
00444 //                      float tmat[4][4];
00445                         int characters, index, character;
00446                         float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
00447                         
00448 //                      bProperty *prop;
00449                         ofsu = ofsv = 0.0;
00450 
00451                         // string = "Frank van Beek";
00452 
00453                         characters = textlen;
00454 
00455                         ima = (struct Image*) tface->tpage;
00456                         if (ima == NULL) {
00457                                 characters = 0;
00458                         }
00459 
00460                         glPushMatrix();
00461                         for (index = 0; index < characters; index++) {
00462                                 // lets calculate offset stuff
00463                                 character = textstr[index];
00464                                 
00465                                 // space starts at offset 1
00466                                 // character = character - ' ' + 1;
00467                                 // ofsu = (character % 10) / 10.0;
00468                                 // ofsv = 1.0 - (floor(character / 10) / 10.0);
00469                                 
00470                                 matrixGlyph(ima->ibuf, character, & centerx, &centery, &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
00471                                 
00472                                 glBegin(GL_POLYGON);
00473                                 // printf(" %c %f %f %f %f\n", character, tface->uv[0][0], tface->uv[0][1], );
00474                                 // glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
00475                                 glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy);
00476 
00477                                 spack(tface->col[0]);
00478                                 // glVertex3fv(v1);
00479                                 glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
00480                                 
00481                                 glTexCoord2f((tface->uv[1][0] - centerx) * sizex + transx, (tface->uv[1][1] - centery) * sizey + transy);
00482                                 spack(tface->col[1]);
00483                                 // glVertex3fv(v2);
00484                                 glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
00485         
00486                                 glTexCoord2f((tface->uv[2][0] - centerx) * sizex + transx, (tface->uv[2][1] - centery) * sizey + transy);
00487                                 spack(tface->col[2]);
00488                                 // glVertex3fv(v3);
00489                                 glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
00490         
00491                                 if(v4) {
00492                                         // glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, 1.0 - (1.0 - tface->uv[3][1]) * sizey - transy);
00493                                         glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, (tface->uv[3][1] - centery) * sizey + transy);
00494                                         spack(tface->col[3]);
00495                                         // glVertex3fv(v4);
00496                                         glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
00497                                 }
00498                                 glEnd();
00499 
00500                                 glTranslatef(advance, 0.0, 0.0);
00501                         }
00502                         glPopMatrix();
00503 
00504                 }
00505 }
00506 
00507 
00508 
00509 void BL_print_gamedebug_line(char* text, int xco, int yco)

00510 {       
00511         persp(0);
00512         cpack(0xFFFFFF);
00513         fmsetfont(G.fonts);
00514         glRasterPos2s(xco, curarea->winy-yco);
00515         fmprstr(text);
00516         persp(1);
00517 }
00518 
00519 int BL_GetWindowHeight()

00520 {
00521         return curarea->winy;
00522 }
00523 int BL_GetWindowWidth()

00524 {
00525         return curarea->winx;
00526 }
00527 
00528 int BL_GetWindowMinY()

00529 {
00530         return curarea->winrct.ymin;
00531 }
00532 int BL_GetWindowMinX()

00533 {
00534         return curarea->winrct.xmin;
00535 }

Generated at Thu Feb 1 13:03:03 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000