mirror of
https://github.com/ysoftdevs/cpp-examples.git
synced 2026-01-16 08:36:50 +01:00
add SDL2 samples
This commit is contained in:
51
sdl/02-sdl2-video/02-sdl2-video.cpp
Normal file
51
sdl/02-sdl2-video/02-sdl2-video.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// 02-sdl2-video.cpp : SDL2 example - initialize video and display image
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "SDL.h"
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[]) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
|
||||
printf("Error initializing SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Window *win = nullptr;
|
||||
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if (win == nullptr){
|
||||
printf("%i\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Renderer *ren = nullptr;
|
||||
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (ren == nullptr){
|
||||
printf("%i\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Surface *bmp = nullptr;
|
||||
bmp = SDL_LoadBMP("smajlik.bmp");
|
||||
if (bmp == nullptr){
|
||||
printf("%i\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Texture *tex = nullptr;
|
||||
tex = SDL_CreateTextureFromSurface(ren, bmp);
|
||||
SDL_FreeSurface(bmp);
|
||||
|
||||
SDL_RenderClear(ren);
|
||||
SDL_RenderCopy(ren, tex, NULL, NULL);
|
||||
SDL_RenderPresent(ren);
|
||||
|
||||
SDL_Delay(2000);
|
||||
|
||||
SDL_DestroyTexture(tex);
|
||||
SDL_DestroyRenderer(ren);
|
||||
SDL_DestroyWindow(win);
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
sdl/02-sdl2-video/smajlik.bmp
Normal file
BIN
sdl/02-sdl2-video/smajlik.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
Reference in New Issue
Block a user