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๋กœ ๋ฐ”๊ฟ”์„œ ํ•ด๋ดค๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค ใ…œใ…œ





๋Œ€์ฒด ๋ญ๊ฐ€ ๋ฌธ์ œ์ผ๊นŒ์š” ใ… ใ