#include
// Screen SurfaceSDL_SURFACE * GSCreen; // Picture SurfaceSdl_surface * gpicture; // Heightmap SurfaceSDL_SURFACE * GHEIGHTMAP; // Texture SurfaceSDL_SURFACE * GTEXTURE
// Lookup TableShort * Glut;
// screen pitch # define pitch (gscreen-> pitch / 4) // screen width # define width 480 // Screen Height # definition of pi # define pi 3.141592653589732384626433832795f
// Physics Items Per Second # Define Physicsfps 100
// Last Iteration's Tick Valueint GlastTick;
void init () {// load-color SDL_Surface * temp = SDL_LoadBMP ( "picture18.bmp"); gPicture = SDL_ConvertSurface (temp, gScreen-> format, SDL_SWSURFACE); SDL_FreeSurface (temp); // temp = Load grayscale SDL_LoadBMP ( "heightmap18.bmp"); gHeightmap = SDL_ConvertSurface (temp, gScreen-> format, SDL_SWSURFACE); SDL_FreeSurface (temp); // load light temp = SDL_LoadBMP ( "texture18.bmp"); gTexture = SDL_ConvertSurface (temp, gScreen -> Format, SDL_swsurface; SDL_FREESURFACE (TEMP);
INT I, J; GLUT = New Short [width * height]; MEMSET (GLUT, 0, SIZEOF (Short) * Width * Height;
IF (SDL_MustLock (GheightMap)) f (SDL_LOCKSURFACE (GHEIGHTMAP) <0) Return; // Here, the grayscale map is mixed according to the same positional pixel point in the phase difference, and for the render, for (i = 1; i
IF (SDL_MustLock (Gheightmap) SDL_Unlocksurface (Gheightmap);
unsigned int blend_add (unsigned int source, unsigned int target) {unsigned int sourcer = (source >> 0) & 0xff; unsigned int sourceg = (source >> 8) & 0xff; unsigned int sourceb = (source >> 16) & 0xff; unsigned int targetr = (target >> 0) & 0xff; unsigned int targetg = (target >> 8) & 0xff; unsigned int targetb = (target >> 16) & 0xff; targetr = Source; targetg = sourceg ; TargetB = sourceb;
IF (Targetr> 0xFF) Targetr = 0xFF; if (targetg> 0xFF) Targetg = 0xff; if (targetb> 0xff) TargetB = 0xff;
Return (Targetg << 8) | (TargetB << 16);}
Void render () {// ask SDL for the Time In MilliseConds Int Tick = SDL_GETTICKS ();
IF (Tick <= GlastTick) {SDL_DELAY (1); Return;}
While (GlastTick GlastTick = 1000 / Physicsfps; // Lock Surface If Needed IF (SDL_Mustlock (Gscreen)) IF (SDL_LOCKSURFACE (Gscreen <0) Return; // rendering here if (SDL_MUSTLOCK (gPicture)) if (SDL_LockSurface (gPicture) <0) return; if (SDL_MUSTLOCK (gTexture)) if (SDL_LockSurface (gTexture) <0) return; // movement path int posx = (int) ((SIN (Tick * 0.000645234) 1) * width / 4); int Posy = (int) ((SIN (Tick * 0.000445234) 1) * Height / 4); INT I, J; for (i = 0 ; i IF (SDL_Mustlock (GPICTURE)) SDL_UNLOCKSURFACE (GPICTURE); // unlock if Needed IF (SDL_Mustlock (Gscreen)) SDL_Unlocksurface (gscreen); // Tell SDL to Update The Whole Gscreen SDL_UPDATERECT (Gscreen, 0, 0, Width, Height); // entry pointint main (int Argc, char * argv []) {// initialize sdl's subsystems if (SDL_INIT (SDL_INIT_VIDEO) <0) {fprintf (stderr, "unable to init SDL:% s / n", SDL_Geterror () ); exit (1);} // Register SDL_Quit to be called at exit; makes sure things are // cleaned up when we quit atexit (SDL_Quit);.. // Attempt to create a WIDTHxHEIGHT window with 32bit pixels gScreen = SDL_SetVideoMode (Width, Height, 32, SDL_SWSURFACE); init (); // if we fail, return error. IF (gscreen == null) {fprintf (stderr, "unable to set up video:% s / n", SDL_GETERROR ()); exit (1);} // main loop: loop forever. While (1) {// render stuff render (); . // Poll for events, and handle the ones we care about SDL_Event event; while (SDL_PollEvent (& event)) {switch (event.type) {case SDL_KEYUP: switch (event.key.keysym.sym) {case SDLK_ESCAPE: / / If escape ispered, return (and thus, quit) return 0;} Break; Case SDL_Quit: return (0);}}} Return 0;