int main() { cout << "This is Tut6-fog1 example running" << endl; //Step 1 is to initialize SDL. Absolutely critical that your SDL application starts with this! if (SDL_Init(SDL_INIT_VIDEO) != 0){ cout << "Error initializing SDL" << endl; return -1; } //Step 2 is to get a screen/window on which we can do some graphics. //create a Videoclass to control the video with SDLVideoclass SDLmain(640,480); if (SDLmain.InitVideo()){ cout << "Video up and running" << endl; }else{ cout << "Error initializing Video" << endl; return 0; } //get the events up and running SDLEventclass SDLevent; glEnable(GL_DEPTH_TEST); //enable depth buffer glShadeModel(GL_SMOOTH); //use smooth shading mode. glEnable(GL_TEXTURE_2D); //setup camera: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,1.33,0.1f,100.0f); //setup the camera glClearColor(0.0,0.0,0.3,0.0); glMatrixMode(GL_MODELVIEW); //switch to modelview matrix for the rest of the example //load the textures stone = new GLTextureclass; stone->Load("stone.bmp"); stone->SetLinearFilter(); wash = new GLTextureclass; wash->Load("wash.bmp"); wash->SetLinearFilter(); //setup blending function: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //timescaling as usual: Uint32 curticks,prevticks; curticks = SDL_GetTicks(); while (!SDLevent.MustQuit()){ //events: SDLevent.ProcessEvent(); prevticks = curticks; curticks = SDL_GetTicks(); timescale = GLfloat(curticks-prevticks)/1000.0; //graphics: drawscene(); } SDL_Quit(); return 0; }
int main() { cout << "This is Tut7-array1 example running" << endl; //Step 1 is to initialize SDL. Absolutely critical that your SDL application starts with this! if (SDL_Init(SDL_INIT_VIDEO) != 0){ cout << "Error initializing SDL" << endl; return -1; } //Step 2 is to get a screen/window on which we can do some graphics. //create a Videoclass to control the video with SDLVideoclass SDLmain(640,480); if (SDLmain.InitVideo()){ cout << "Video up and running" << endl; }else{ cout << "Error initializing Video" << endl; return 0; } //get the events up and running SDLEventclass SDLevent; glEnable(GL_DEPTH_TEST); //enable depth buffer glShadeModel(GL_SMOOTH); //use smooth shading mode. //setup camera: glMatrixMode(GL_PROJECTION); gluPerspective(45.0f,1.33,0.1f,100.0f); //setup the camera glClearColor(0.0,0.0,0.2,0.0); glMatrixMode(GL_MODELVIEW); glTranslatef(0,0,-7); Setup(); Uint32 curticks,prevticks; curticks = SDL_GetTicks(); GLfloat rotate=34; while (!SDLevent.MustQuit()){ SDLevent.ProcessEvent(); prevticks = curticks; curticks = SDL_GetTicks(); rotate += 45*GLfloat(curticks-prevticks)/1000.0; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0,0,-7); glRotatef(rotate,0,1,0); Draw(); } SDL_Quit(); return 0; }
int main() { cout << "This is Tut6-fog1 example running" << endl; //Step 1 is to initialize SDL. Absolutely critical that your SDL application starts with this! if (SDL_Init(SDL_INIT_VIDEO) != 0){ cout << "Error initializing SDL" << endl; return -1; } //Step 2 is to get a screen/window on which we can do some graphics. //create a Videoclass to control the video with SDLVideoclass SDLmain(640,480); if (SDLmain.InitVideo()){ cout << "Video up and running" << endl; }else{ cout << "Error initializing Video" << endl; return 0; } //get the events up and running SDLEventclass SDLevent; setup(); GLfloat rotx,roty; GLfloat distance; rotx = 0; roty = 0; distance = 10; Uint32 curticks,prevticks; GLfloat timescale; curticks = SDL_GetTicks(); cout << "Move the cube further and closer with the UP/DOWN arrow keys" << endl; cout << "Press ESC to quit" << endl; while (!SDLevent.MustQuit()){ SDLevent.ProcessEvent(); //events: //timescale prevticks = curticks; curticks = SDL_GetTicks(); timescale = GLfloat(curticks-prevticks)/1000.0; //rotation rotx += timescale*60; roty += timescale*15; if (SDLevent.GetKey(SDLK_UP)) if (distance < 21) distance += timescale*4; if (SDLevent.GetKey(SDLK_DOWN)) if (distance > 4) distance -= timescale*4; //graphics: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //setup modelview matrix: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0,0,-distance); glRotatef(rotx,1,0,0); glRotatef(roty,0,1,0); drawbox(); SDL_GL_SwapBuffers(); } SDL_Quit(); return 0; }
int main() { //The first part of this code will by now be pretty standard to you: cout << "This is Tut4-lists2 example running" << endl; //Step 1 is to initialize SDL. Absolutely critical that your SDL application starts with this! if (SDL_Init(SDL_INIT_VIDEO) != 0){ cout << "Error initializing SDL" << endl; return -1; } //Step 2 is to get a screen/window on which we can do some graphics. //create a Videoclass to control the video with SDLVideoclass SDLmain(640,480); if (SDLmain.InitVideo()){ cout << "Video up and running" << endl; }else{ cout << "Error initializing Video" << endl; return 0; } //get the events up and running SDLEventclass SDLevent; //some GL setup routines glEnable(GL_DEPTH_TEST); //enable depth buffer glShadeModel(GL_SMOOTH); //use smooth shading mode. //setup camera: glMatrixMode(GL_PROJECTION); gluPerspective(45.0f,1.33,0.1f,100.0f); //setup the camera //setup modelview matrix: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.0,0.0,0.2,0.0); //Ok lets start with the display list: makelists(); GLfloat rot = 0.0; Uint32 curticks,prevticks; GLfloat timescale; curticks = SDL_GetTicks(); //the heights of the piramids GLfloat height1,height2; int mod2; height1 = 2.0; height2 = 2.0; mod2 = FALSE; cout << "Use Left and Right to rotate piramids" << endl; cout << "Change height of piramid 1 with A and Z" << endl; cout << "Change height of piramid 2 with S and X" << endl; //main loop: while (!SDLevent.MustQuit()){ SDLevent.ProcessEvent(); //main loop 1 - events //timescale: prevticks = curticks; curticks = SDL_GetTicks(); timescale = GLfloat(curticks-prevticks)/1000.0; //check rotation keys if (SDLevent.GetKey(SDLK_LEFT)) rot += timescale*90; if (SDLevent.GetKey(SDLK_RIGHT)) rot -= timescale*90; //check height change keys //piramid1 - use immediate recompile of displaylist method if (SDLevent.GetKey(SDLK_a)) if (height1 < 6.0){ height1 += timescale*1.5; updatelist(displaylists,height1); } if (SDLevent.GetKey(SDLK_z)) if (height1 > 0.0){ height1 -= timescale*1.5; updatelist(displaylists,height1); } //piramid2 - recompile only if needed with GL_COMPILE_AND_EXECUTE method if (SDLevent.GetKey(SDLK_s)) if (height2 < 6.0){ height2 += timescale*1.5; mod2 = TRUE; } if (SDLevent.GetKey(SDLK_x)) if (height2 > 0.0){ height2 -= timescale*1.5; mod2 = TRUE; } //main loop 2 - graphics glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //we draw 2 piramids: //piramid 1: to the left glLoadIdentity(); glTranslatef(-5.0,0.0,-20.0); glRotatef(rot,0.0,1.0,0.0); //call the display list to draw the piramid rather than the procedure. glCallList(displaylists); //piramid 2: to the right glLoadIdentity(); glTranslatef(5.0,0.0,-20.0); glRotatef(-rot,0.0,1.0,0.0); //call the display list to draw the piramid rather than the procedure. if (mod2){ //the height2 changed! glNewList(displaylists+1,GL_COMPILE_AND_EXECUTE); drawpiramid(height2); glEndList(); }else{ glCallList(displaylists+1); } SDL_GL_SwapBuffers(); } SDL_Quit(); return 0; }
int main() { cout << "This is Tut6-compress example running" << endl; //Step 1 is to initialize SDL. Absolutely critical that your SDL application starts with this! if (SDL_Init(SDL_INIT_VIDEO) != 0){ cout << "Error initializing SDL" << endl; return -1; } //Step 2 is to get a screen/window on which we can do some graphics. //create a Videoclass to control the video with SDLVideoclass SDLmain(640,480); if (SDLmain.InitVideo()){ cout << "Video up and running" << endl; }else{ cout << "Error initializing Video" << endl; return 0; } //some gl setup parameters glEnable(GL_DEPTH_TEST); //enable depth buffer glShadeModel(GL_SMOOTH); //use smooth shading mode. //setup camera: glMatrixMode(GL_PROJECTION); gluPerspective(45.0f,1.33,0.1f,100.0f); //setup the camera glClearColor(0.0,0.0,0.1,0.0); //the same color as the fog (nice green toxic fog hey :) //from now on use the modelview matrix for manipulation! glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); //get the events up and running SDLEventclass SDLevent; //setup texture: Textureclass texture; //comment out this line to disable Mipmapping texture.Mipmap(); //comment out this line if you like to disable texture compression texture.Compress(); if (!texture.Load("sunset.bmp")){ cout << "texture load error, halting" << endl; return -1; } texture.SetLinearFilter(); texture.Activate(); //use this texture and this texture only! GLfloat rot=0; Uint32 curticks,prevticks; curticks = SDL_GetTicks(); compress_setup(); cout << "press ESC to quit" << endl; while (!SDLevent.MustQuit()){ //events SDLevent.ProcessEvent(); //calculate the rotation value prevticks = curticks; curticks = SDL_GetTicks(); rot += 60*GLfloat(curticks-prevticks)/1000.0; //graphics glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0,0,-15); glRotatef(rot,0,1,0); Draw(); SDL_GL_SwapBuffers(); } return 0; }