Advertisement
Guest User

Untitled

a guest
Aug 31st, 2011
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. /*
  2. ** Ortho test
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <GLES/gl.h>
  8. #include "SDL.h"
  9. #include "PDL.h"
  10.  
  11. SDL_Surface *surface = NULL;               // Screen surface to retrieve width/height information
  12.  
  13. GLfloat square[] = {
  14.     0.25, 0.25, 0.0,
  15.     0.75, 0.25, 0.0,
  16.     0.25, 0.75, 0.0,
  17.     0.75, 0.75, 0.0
  18.     };
  19.  
  20. int init( void )
  21. {
  22.   glClearColor (0.0f, 0.0f, 0.7f, 1.0f);
  23.  
  24.   glMatrixMode(GL_PROJECTION);
  25.   glLoadIdentity();
  26.   glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
  27.   glMatrixMode(GL_MODELVIEW);
  28.  
  29.   return 1;
  30. }
  31.  
  32. void shut( void )
  33. {
  34. }
  35.  
  36. void display()
  37. {
  38.   glLoadIdentity();
  39.   glClear (GL_COLOR_BUFFER_BIT);
  40.  
  41.   glEnableClientState(GL_VERTEX_ARRAY);
  42.   glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  43.   glVertexPointer(3, GL_FLOAT, 0, square);
  44.   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  45.   glDisableClientState(GL_VERTEX_ARRAY);
  46.  
  47.   SDL_GL_SwapBuffers();
  48. }
  49.  
  50. int main( int argc, char** argv )
  51. {
  52.   // Initialize the SDL library with the Video subsystem
  53.   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
  54.   atexit(SDL_Quit);
  55.    
  56.   // start the PDL library
  57.   PDL_Init(0);
  58.   atexit(PDL_Quit);
  59.  
  60.   PDL_SetOrientation(PDL_ORIENTATION_90);
  61.    
  62.   // Set the video mode to full screen with OpenGL-ES support
  63.   // use zero for width/height to use maximum resolution
  64.   surface = SDL_SetVideoMode(0, 0, 0, SDL_OPENGL);
  65.  
  66.   init();
  67.  
  68.  
  69.   // Event descriptor
  70.   SDL_Event Event;
  71.   SDL_bool paused = SDL_FALSE;
  72.   SDL_bool done = SDL_FALSE;
  73.  
  74.   while( !done )
  75.   {
  76.     // Render our scene
  77.     display();
  78.  
  79.     SDL_bool gotEvent;
  80.     if (paused)
  81.     {
  82.       SDL_WaitEvent(&Event);
  83.       gotEvent = SDL_TRUE;
  84.     }
  85.     else
  86.     {
  87.       gotEvent = SDL_PollEvent(&Event);
  88.     }
  89.        
  90.     while( gotEvent )
  91.     {
  92.       switch (Event.type)
  93.       {
  94.         // List of keys that have been pressed
  95.         case SDL_KEYDOWN:
  96.           switch (Event.key.keysym.sym)
  97.           {
  98.             case PDLK_GESTURE_BACK: /* also maps to ESC */
  99.               if( PDL_GetPDKVersion() >= 200 )
  100.               {
  101.                 // standard behavior is to minimize to a card when you perform a back
  102.                 // gesture at the top level of the app
  103.                 PDL_Minimize();
  104.               }
  105.               break;
  106.  
  107.             default:
  108.               break;
  109.           }
  110.           break;
  111.  
  112.         case SDL_ACTIVEEVENT:
  113.           if( Event.active.state == SDL_APPACTIVE )
  114.           {
  115.             paused = !Event.active.gain;
  116.           }
  117.           break;
  118.  
  119.         case SDL_QUIT:
  120.           // We exit anytime we get a request to quit the app
  121.           // all shutdown code is registered via atexit() so this is clean.
  122.           done = SDL_TRUE;
  123.           break;
  124.  
  125.         default:
  126.           break;
  127.       }
  128.       gotEvent = SDL_PollEvent(&Event);
  129.     }
  130.   }
  131.  
  132.   shut();
  133.  
  134.   return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement