1 lesson
This commit is contained in:
parent
2bf6fdb5a1
commit
636409281a
Before Width: | Height: | Size: 900 KiB After Width: | Height: | Size: 900 KiB |
25
testSDL/Lesson1/main.cpp
Normal file
25
testSDL/Lesson1/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0 )
|
||||
{
|
||||
cout << "SDL_Init error\n";
|
||||
return 1;
|
||||
}
|
||||
SDL_Window* window = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if (window == nullptr)
|
||||
{
|
||||
cout << "Window create error\n";
|
||||
return 1;
|
||||
}
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED || SDL_RENDERER_PRESENTVSYNC);
|
||||
if (renderer == nullptr)
|
||||
{
|
||||
cout << "Renderer error\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
|
||||
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
|
||||
if (win == nullptr){
|
||||
std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (ren == nullptr){
|
||||
std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
SDL_Surface *bmp = SDL_LoadBMP("../res/Lesson1/hello.bmp");
|
||||
if (bmp == nullptr){
|
||||
std::cout << "SDL_LoadBMP Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
|
||||
SDL_FreeSurface(bmp);
|
||||
if (tex == nullptr){
|
||||
std::cout << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user