SDL Learning 1

xiaoxiao2021-03-06  22

#include

#include

#include

#include

#include

#include

#include "Tunnel.h" // SDL Stuff SDL_Surface * screen; SDL_Surface * bBuffer; SDL_Surface * Image; SDL_Rect rScreen; SDL_Rect rBuffer; static __int64 timerstart; static __int64 timerfrq; static void Tunnel_Timer () {QueryPerformanceCounter ((LARGE_INTEGER *) & timerstart ); QueryPerformanceFrequency ((LARGE_INTEGER *) & timerfrq);} static double Tunnel_GetTime () {__int64 a; QueryPerformanceCounter ((LARGE_INTEGER *) & a); return (double) (a - timerstart) / (double) (timerfrq);} // -------------------------------------------------- ------------------------------ int main (int Argc, char ** argv) {int flag = SDL_swsurface; // Initialization time tunnel_timer (); // Initialization SDL SDL_INIT (SDL_INIT_VIDEO); // Setting surface display mode Screen = SDL_SETVIDEODE (400, 300, 32, flag); // Create an empty surface BBuffer = SDL_creatergbsurface (SDL_HWSURFACE, SCREEN -> w, screen-> h, screen-> format-> bitsPerpixel, screen-> format-> rmask, screen-> format-> gmask, screen-> format-> bmask, screen-> format-> amask; // Load a bitmap to the action page image = SDL_LOADBMP ("tunnel_map.bmp"); // alpha 1.BMP tunnel_map.bmp if (! Bbuffer ||! Image) {printf ("error: i can't load or create bmp !!! / n / n"); return -1;} // conversion operation page Format Screen-> Format Image = SDL_CONVERTSURFACE (Image, Screen-> Format, SDL_HWSurface); // Setting the rectangular size RBuffer.x = 0; rBuffer.y = 0; rBuffer.w = bbuffer-> w; // 320 RBuffer. h = bBuffer-> h; // 240 SDL_EventState (SDL_ACTIVEEVENT, SDL_IGNORE); SDL_EventState (SDL_MOUSEMOTION, SDL_IGNORE); SDL_ShowCursor (SDL_DISABLE); Tunnel.Set (400, 300); // Dimension du tunnel Tunnel.Precalc (32); // Diametre du tunnel while (SDL_POLLEVENT (NULL) == 0) {float ftime = tunnel_gettime (); SDL_LOCKSURFACE (BBuffer);

SDL_LockSurface (Image); Tunnel.Draw (bBuffer, Image, 180 * sin (fTime), fTime * 100); SDL_UnlockSurface (bBuffer); SDL_UnlockSurface (Image); SDL_BlitSurface (bBuffer, NULL, screen, & rBuffer); SDL_UpdateRect (screen, 0, 0, 0, 0);} tunnel.free (); return 0;} // # incrude # include

#include

#include

#include

#include

#ifdef win32 #include

#ENDIF #include

#define pi 3.1415926535f // Une Petite class tunnel class ctunnel {public: int W; // hauteur int h; // limited, mais ca served pas int * tangle; // lookup des ang gles int * TDEPTH; // Lookup Des Profondeur Void Set (int, int); Void PRecalc (int); Void Draw (SDL_SURFACE * Buffer, SDL_SURFACE * MAP, INT, INT); Void Free (Void);} tunnel; // SERT A Alluer La Memoire Pour Lookups .... Void CTunnel :: Set (int width, int = height; tangle = new int [w * h]; tdepth = new int = new int [w * h] } // Precalcul des Tables void CTunnel :: Precalc (int Diametre) // Diameter = 8, 16, 32, 64 ..... {INT CX = W / 2; int Cy = h / 2; for (int X = 0; x

Pixels; map_dat = (uint32 *) map-> pixels; // on boucle sur l'EcRan for (int x = 0; x

W];}}} void ctunnel :: free (void) {// on libre les lookups .... delete [] tangle; delete [] tdepth;}

转载请注明原文地址:https://www.9cbs.com/read-39996.html

New Post(0)