Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SDL2/SDL.h>
- using namespace std;
- // La firma del main al parecer es muy sensible en SDL
- int main(int argc, char *argv[])
- {
- // Inicializa SDL
- SDL_Init(SDL_INIT_VIDEO);
- // Creamos una ventana
- SDL_Window *ventana = SDL_CreateWindow(
- "Ventana SDL", // Titulo
- SDL_WINDOWPOS_UNDEFINED, // Posicion inicial X en el escritorio de windows (sin definir)
- SDL_WINDOWPOS_UNDEFINED, // Posicion inicial Y en el escritorio de windows (sin definir)
- 640, // Tamaño horizontal
- 480, // Tamaño vertical
- SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE // Ventana visible | ventana opengl | ventana redimensionable
- );
- // Creamos el renderizador (con aceleración por hardware!!!1!11!!)
- SDL_Renderer *pintador = SDL_CreateRenderer(ventana,-1,SDL_RENDERER_ACCELERATED);
- // Creamos una superficie leyendo la imagen .bmp
- SDL_Surface *imagen = SDL_LoadBMP("standingmario.bmp");
- // Creamos la textura en el renderizador
- SDL_Texture *textura = SDL_CreateTextureFromSurface(pintador,imagen);
- // Bucle infinito...
- while(1)
- {
- // Cogemos eventos
- SDL_Event e;
- if(SDL_PollEvent(&e))
- {
- // Si el evento es de salida (X de la ventana supongo...) sale del bucle.
- if(e.type == SDL_QUIT) break;
- }
- SDL_Delay(17); // mas o menos 60 fps...
- // Limpia el renderer
- SDL_RenderClear(pintador);
- // Copia la textura al renderer
- SDL_RenderCopy(pintador,textura,NULL,NULL);
- // Dibuja la imagen...
- SDL_RenderPresent(pintador);
- }
- // Liberamos memoria y destruimos objetos...
- SDL_FreeSurface(imagen);
- SDL_DestroyTexture(textura);
- SDL_DestroyRenderer(pintador);
- SDL_DestroyWindow(ventana);
- //Adios
- SDL_Quit();
- return 0;
- }
Add Comment
Please, Sign In to add comment