C:/Documents and Settings/mtauraso/Desktop/proj3/projectX/main.cpp

Go to the documentation of this file.
00001 /*
00002  * Small SDL example to demonstrate dynamically loading 
00003  * OpenGL lib and functions
00004  *
00005  * (FYI it was supposed to look like snow in the wind or something...)
00006  *
00007  * Compile with :
00008  * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL
00009  *
00010  * You can specify a different OpenGL lib on the command line, i.e. :
00011  * ./testdyngl  /usr/X11R6/lib/libGL.so.1.2
00012  * or
00013  * ./testdyngl  /usr/lib/libGL.so.1.0.4496
00014  *
00015  */
00016 
00017 
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <string>
00021 #include <iostream>
00022 
00023 #include "SDL.h"
00024 #include "Person.h"
00025 #include "SDL_image.h"
00026 #include "SDL_mixer.h"
00027 #include "Level.h"
00028 
00029 #include "List.h"
00030 #include "Parser.h"
00031 #include "CollisionHandler.h"
00032 #include "CommandManager.h"
00033 #include "Command.h"
00034 
00035 #include "Screen.h"
00036 
00037 using namespace std;
00038 
00039 int main(int argc,char *argv[])
00040 {               
00041         //string levelfile = "levels/level";
00042         //string levelfile = "levels/pipes2";
00043         //string levelfile = "levels/pipes3";
00044         string levelfile = "levels/factory";
00045         
00046         /*
00047         List *list = Parser::parse("textures/jesus.txt");
00048     //cout << newList->getString();
00049 
00050         List *newList = list;
00051     while(!newList->empty()) {
00052         cout << newList->getString() << endl;
00053         newList = newList->rest();
00054     }
00055     delete list;
00056 
00057         return 0;
00058         */
00059 
00060         SDL_Event event;
00061         
00062 
00063         Screen* screen = Screen::instance();
00064 
00065         //Person person;
00066     
00067         //Initialize SDL_mixer
00068     if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
00069     {
00070         return false;    
00071     }
00072 
00073         Mix_AllocateChannels( 16 );
00074 
00075         //These are used to limit the frame rate
00076         //int FRAMERATE = Screen::FRAMERATE;
00077         int ticks = SDL_GetTicks();
00078 
00079         glfuncs* f = glfuncs::instance();
00080 
00081         Level theonlylevel = Level();
00082         theonlylevel.levelLoad(levelfile);
00083 
00084         //GLuint base = f->BuildFont();
00085 
00086 
00087         GLfloat whiteCoords[4];
00088         SDL_Surface *whiteSurface = f->load_image("whiteBG.png");
00089         int whiteBG = f->SDL_GL_LoadTexture(whiteSurface, whiteCoords);
00090 
00091         GLfloat scramCoords[4];
00092         SDL_Surface *scramSurface = f->load_image("scramble.png");
00093         int scram = f->SDL_GL_LoadTexture(scramSurface, scramCoords);
00094 
00095 
00096         bool looping = true;
00097         bool leave = false;
00098 
00099         do
00100         {
00101                 do
00102                 {
00103                         // Clear OpenGL screen
00104                         f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00105 
00106                         SDL_Rect screenRect = screen->getScreenRect();
00107                         screenRect.x = 0;
00108                         screenRect.y = 0;
00109                         screen->drawScreen(whiteBG,whiteCoords,screenRect);
00110 
00111                         /*SDL_Rect quad;
00112                         quad.h = 128;
00113                         quad.w = 128;
00114                         quad.x = 240;
00115                         quad.y = 240;
00116                         for(int i = 0; i < 4; i++) {
00117                                 screen->drawLevel(texture,texCoords,quad);
00118                                 quad.x += 128;
00119                         }*/
00120 
00121                         //This runs if we are trying to run frames in too rapid succession
00122                         
00123                         while((SDL_GetTicks() - ticks) < 1000/Screen::FRAMERATE)
00124                         {
00125                                 //Just wait until we can do a frame again
00126                                 Sleep(0);
00127                         }
00128 
00129                         if(!theonlylevel.update())
00130                                 break;
00131                         //theonlylevel.update(SDL_GetTicks() - ticks);
00132 
00133                         theonlylevel.draw();
00134 
00135                         //reset for the next time we want to update
00136                         ticks = SDL_GetTicks();
00137 
00138                         
00139 
00140                         SDL_Rect scramRect;
00141                         scramRect.w = 51;
00142                         scramRect.h = 81;
00143                         scramRect.x = 5;
00144                         scramRect.y = screen->getScreenRect().h - 80;
00145                         screen->drawScreen(scram,scramCoords,scramRect);
00146 
00147                         //person.draw();
00148 
00149                         //I don't know why this works now, but it does...
00150                         /*
00151                         f->glColor4f(0,1,1,1);
00152                         SDL_Rect textRect;
00153                         textRect.w = 164;
00154                         textRect.h = 32;
00155                         textRect.x = 700;
00156                         textRect.y = 5;
00157                         screen->drawScreen(whiteBG,whiteCoords,textRect);
00158                         f->glColor4f(1,1,1,1);
00159 
00160                         f->glRasterPos2f(textRect.x+5,textRect.y+textRect.h-3);
00161                         f->glPrint("Jesus Juice.", base);
00162                         */
00163                         //end experimental text code
00164 
00165 
00166                         f->glFinish();
00167                         SDL_GL_SwapBuffers();
00168 
00169                         //person.control();
00170                         //screen->control();
00171 
00172                         
00173                         while(SDL_PollEvent(&event))
00174                         {
00175                                 if(event.type & SDL_KEYDOWN) {
00176                                         switch( event.key.keysym.sym ) 
00177                                         {
00178                                         case SDLK_ESCAPE:
00179                                                 leave = true;
00180                                                 break;
00181                                         default:
00182                                                 break;
00183                                         }
00184                                 }
00185                         }
00186 
00187                         //SDL_Delay(20);
00188                 } while(!leave);
00189                 
00190                 theonlylevel.reset();
00191 
00192         }while(!leave);
00193         
00194         
00195 
00196 
00197 
00198         //f->KillFont(base);
00199 
00200         SDL_Quit();
00201         return 0;
00202 }

Generated on Sat Apr 22 15:05:20 2006 for ProjectX by  doxygen 1.4.6-NO