Vixente

SDL Test

Jun 17th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <SDL2/SDL.h>
  3.  
  4. using namespace std;
  5.  
  6. // La firma del main al parecer es muy sensible en SDL
  7. int main(int argc, char *argv[])
  8. {
  9.     // Inicializa SDL
  10.     SDL_Init(SDL_INIT_VIDEO);
  11.     // Creamos una ventana
  12.     SDL_Window *ventana = SDL_CreateWindow(
  13.        "Ventana SDL",                       // Titulo
  14.        SDL_WINDOWPOS_UNDEFINED,             // Posicion inicial X en el escritorio de windows (sin definir)
  15.        SDL_WINDOWPOS_UNDEFINED,             // Posicion inicial Y en el escritorio de windows (sin definir)
  16.        640,                                 // Tamaño horizontal
  17.        480,                                 // Tamaño vertical
  18.        SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE          // Ventana visible | ventana opengl | ventana redimensionable
  19.        );
  20.  
  21.    // Creamos el renderizador (con aceleración por hardware!!!1!11!!)
  22.    SDL_Renderer *pintador = SDL_CreateRenderer(ventana,-1,SDL_RENDERER_ACCELERATED);
  23.    // Creamos una superficie leyendo la imagen .bmp
  24.    SDL_Surface *imagen = SDL_LoadBMP("standingmario.bmp");
  25.    // Creamos la textura en el renderizador
  26.    SDL_Texture *textura = SDL_CreateTextureFromSurface(pintador,imagen);
  27.  
  28.    // Bucle infinito...
  29.    while(1)
  30.    {
  31.        // Cogemos eventos
  32.        SDL_Event e;
  33.        if(SDL_PollEvent(&e))
  34.        {
  35.            // Si el evento es de salida (X de la ventana supongo...) sale del bucle.
  36.            if(e.type == SDL_QUIT) break;
  37.  
  38.        }
  39.        SDL_Delay(17); // mas o menos 60 fps...
  40.        // Limpia el renderer
  41.        SDL_RenderClear(pintador);
  42.        // Copia la textura al renderer
  43.        SDL_RenderCopy(pintador,textura,NULL,NULL);
  44.        // Dibuja la imagen...
  45.        SDL_RenderPresent(pintador);
  46.    }
  47.    // Liberamos memoria y destruimos objetos...
  48.    SDL_FreeSurface(imagen);
  49.    SDL_DestroyTexture(textura);
  50.    SDL_DestroyRenderer(pintador);
  51.    SDL_DestroyWindow(ventana);
  52.  
  53.    //Adios
  54.    SDL_Quit();
  55.    return 0;
  56.  
  57. }
Add Comment
Please, Sign In to add comment