๋ค ํ๋ ธ๋ค. ์ด๊ฑฐ ๋ค์ ์ฝ์ด๋ณด๋๋ก ํ์.
๊ทธ๋ฆฌ๊ณ ๋น์ฃผ์ผ ์คํ๋์ค ์ค์นํ์ผ๋ฉด ๋ฆฌ๋ถํ ๊ผญ ํ๊ณ ... ใ ก.ใ ก;
https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/msvc2019/index.php
์ ํ๋ธ ์์ ์ฐธ๊ณ - https://www.youtube.com/watch?v=7nkKVyt0DsY
๋น์ฃผ์ผ ์คํ๋์ค 2022 ์ค์น
๊ทผ๋ฐ ์๊ธด ๊ฒ ๋น์ฃผ์ผ ์คํ๋์ค 2022 ์ค์น๋ ์ํด๋จ๋ค?
๊ฐ๋ณ ๊ตฌ์ฑ ์์์์ "C++๋ฅผ ์ฌ์ฉํ ๋ฐ์คํฌํฑ ๊ฐ๋ฐ"๊ณผ "C++๋ฅผ ์ฌ์ฉํ ๊ฒ์ ๊ฐ๋ฐ" ์ ํ
์ค์น ์ค...
SDL ์ค์น
SDL ํํ์ด์ง - https://www.libsdl.org/SDL Release (GitHub) - https://github.com/libsdl-org/SDL/releases/tag/release-2.24.0Development Libraries ๋ค์ด๋ก๋
์คํฌ๋กค ์ญ์ญ ๋ด๋ฆฌ๋ฉด~ SDL2-devel-2.24.0-VC.zip ๋ค์ด๋ก๋
๊ทธ๋ฆฌ๊ณ ์ถ๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
SDL image - https://github.com/libsdl-org/SDL_image/tree/main/VisualCSDL mixer - https://github.com/libsdl-org/SDL_mixer
GitHub์์ ์์ ๋ ๊ฐ ์์ค์ฝ๋ ํต์งธ๋ก ๋ค์ด๋ก๋์์ ์์ถ ํธ๋๋ฐ ์ค๋ฅ๋จ.
SHIFT + ๋ง์ฐ์ค ์ฐํด๋ฆญํด์ ๋ฐ๋์ง ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์์ถ ํ๊ธฐ ์๋ฃ.
์์ค์ฝ๋ ์
๋ ฅํ๊ณ ์คํํด๋ณด๊ธฐ
๋น์ฃผ์ผ ์คํ๋์ค 2022 ์คํ -> ๋น ํ๋ก์ ํธ ์ ํmain.cpp ์ถ๊ฐ
main.cpp์ ์๋ ์์ค ์ฝ๋ ๋ถ์ฌ๋ฃ๊ณ ์คํํด๋ณด๊ธฐ (๋น์ฐํ ์๋จ)
#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>
#include <iostream>
#define WIDTH 1280
#define HEIGHT 720
int main(int argc, char* argv[]) {
// variable declarations
SDL_Window* win = NULL;
SDL_Renderer* renderer = NULL;
SDL_Texture* img = NULL;
// Initialize SDL.
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;
// create the window and renderer
// note that the renderer is accelerated
win = SDL_CreateWindow("Image Loading", 0, 78, WIDTH, HEIGHT, 0);
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
// load our image
img = IMG_LoadTexture(renderer, "C:/Users/BoostMyTool/Desktop/image.jpg");
if (img == nullptr) {
std::cout << "IMG_LoadTexture Error: " << SDL_GetError() << "\n";
return 1;
}
int w, h; // texture width & height
SDL_QueryTexture(img, NULL, NULL, &w, &h); // get the width and height of the texture
// put the location where we want the texture to be drawn into a rectangle
// I'm also scaling the texture 2x simply by setting the width and height
SDL_Rect texr; texr.x = 0; texr.y = 0; texr.w = w; texr.h = h;
unsigned int lastUpdateTime = 0;
// main loop
while (1) {
// event handling
SDL_Event e;
if (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT)
break;
else if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_ESCAPE)
break;
}
// paint the image once every 30ms, i.e. 33 images per second
if (lastUpdateTime + 30 < SDL_GetTicks()) {
lastUpdateTime = SDL_GetTicks();
// clear the screen
SDL_RenderClear(renderer);
// copy the texture to the rendering context
SDL_RenderCopy(renderer, img, NULL, &texr);
// flip the backbuffer
// this means that everything that we prepared behind the screens is actually shown
SDL_RenderPresent(renderer);
}
}
SDL_DestroyTexture(img);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(win);
return 0;
}
์ด๊ฒ๋ ํด๋ด์ผ์ง
https://gist.github.com/superzazu/c0f923181a9cdb82c6d84dcf8b61c8c5
#include <stdio.h>
#include <SDL.h>
int main(void) {
SDL_Init(SDL_INIT_AUDIO);
// the representation of our audio device in SDL:
SDL_AudioDeviceID audio_device;
// opening an audio device:
SDL_AudioSpec audio_spec;
SDL_zero(audio_spec);
audio_spec.freq = 44100;
audio_spec.format = AUDIO_S16SYS;
audio_spec.channels = 1;
audio_spec.samples = 1024;
audio_spec.callback = NULL;
audio_device = SDL_OpenAudioDevice(
NULL, 0, &audio_spec, NULL, 0);
// pushing 3 seconds of samples to the audio buffer:
float x = 0;
for (int i = 0; i < audio_spec.freq * 3; i++) {
x += .010f;
// SDL_QueueAudio expects a signed 16-bit value
// note: "5000" here is just gain so that we will hear something
int16_t sample = sin(x * 4) * 5000;
const int sample_size = sizeof(int16_t) * 1;
SDL_QueueAudio(audio_device, &sample, sample_size);
}
// unpausing the audio device (starts playing):
SDL_PauseAudioDevice(audio_device, 0);
SDL_Delay(3000);
SDL_CloseAudioDevice(audio_device);
SDL_Quit();
return 0;
}
Include ํด๋ ์ถ๊ฐ
ํ๋ก์ ํธ ์์ฑ
๊ตฌ์ฑ ์์ฑ -> C/C++ -> ์ผ๋ฐ -> ์ถ๊ฐ ํฌํจ ๋๋ ํ ๋ฆฌ
๋ค์ด๋ฐ์ SDL2 ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํด๋ ์ถ๊ฐSDL image์ SDL mixer๋ ์ถ๊ฐ
Lib ํด๋ ์ถ๊ฐ
๊ตฌ์ฑ ์์ฑ -> ๋ง์ปค -> ์ผ๋ฐ -> ์ถ๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋๋ ํ ๋ฆฌ
๊ตฌ์ฑ ์์ฑ -> ๋ง์ปค -> ์ ๋ ฅ -> ์ถ๊ฐ ์ข ์์ฑ
... ๋ ์๋จ ;ใ
ก.,ใ
ก?ใ
๋ค์ ๋ฒ์ ๋ค์ ํด๋ณด๋ ๊ฑธ๋ก...
๋ค์ด๋ก๋ ํ์ผ
์์ ๋ค์ด๋ฐ์ ์ค์นํ ํ์ผ๋ค