1๋ฒ
#include <SDL.h>
#include <cstdio>
//Screen dimension constants
const static int SCREEN_WIDTH = 1280;
const static int SCREEN_HEIGHT = 720;
int main(int argc, char* args[])
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("SDL could not initialize! SDL_Error: %s
", SDL_GetError());
}
else
{
//Create window
window = SDL_CreateWindow("SDL2_2048", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL)
{
printf("Window could not be created! SDL_Error: %s
", SDL_GetError());
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface(window);
//Fill the surface white
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFA, 0xF8, 0xEF));
//Update the surface
SDL_UpdateWindowSurface(window);
//Wait two seconds
SDL_Delay(2000);
}
}
//Destroy window
SDL_DestroyWindow(window);
//Quit SDL subsystems
SDL_Quit();
return 0;
}
2๋ฒ
#include <SDL.h>
#include <cstdio>
//Screen dimension constants
const static int SCREEN_WIDTH = 1280;
const static int SCREEN_HEIGHT = 720;
int main(int argc, char* args[])
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Renderer* renderer = NULL;
//Initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
printf("SDL could not initialize! SDL_Error: %s
", SDL_GetError());
}
else
{
//Create window
window = SDL_CreateWindow("SDL2_2048", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL)
{
printf("Window could not be created! SDL_Error: %s
", SDL_GetError());
}
else
{
//Get window surface
renderer = SDL_CreateRenderer(window, -1, 0);
//Fill the surface white
SDL_SetRenderDrawColor(renderer, 250, 248, 239, 255);
//Update the surface
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
//Wait two seconds
SDL_Delay(2000);
SDL_DestroyRenderer(renderer);
}
}
//Destroy window
SDL_DestroyWindow(window);
//Quit SDL subsystems
SDL_Quit();
return 0;
}
1๋ฒ์ ์ ๋์๊ฐ๋๋ฐ,
1๋ฒ์์ surface๋ง renderer๋ก ๋ฐ๊ฟ์ ํด๋ดค๋๋ฐ ์๋ฌ๊ฐ ๋ฉ๋๋ค ใ ใ
๋์ฒด ๋ญ๊ฐ ๋ฌธ์ ์ผ๊น์ ใ
ใ
๋๊ธ 0