๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/C, C++ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค 2022์—์„œ SDL2.24.0 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•˜๊ธฐ

๐ŸŽฎinspirer9 2022. 9. 29. 15:17
728x90
๋ฐ˜์‘ํ˜•

๋‹ค ํ‹€๋ ธ๋‹ค. ์ด๊ฑฐ ๋‹ค์‹œ ์ฝ์–ด๋ณด๋„๋ก ํ•˜์ž.

๊ทธ๋ฆฌ๊ณ  ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค ์„ค์น˜ํ–ˆ์œผ๋ฉด ๋ฆฌ๋ถ€ํŒ… ๊ผญ ํ•˜๊ณ ... ใ…ก.ใ…ก;

https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/msvc2019/index.php

 

Lazy Foo' Productions - Setting up SDL 2 on Visual Studio 2019 Community

Setting up SDL 2 on Visual Studio 2019 Community Last Updated 9/17/22 1)First thing you need to do is download SDL 2 headers and binaries. You will find them on the SDL GitHub, specifically on this page. You'll want to download the Visual C++ development l

lazyfoo.net

 

์œ ํŠœ๋ธŒ ์˜์ƒ ์ฐธ๊ณ  - https://www.youtube.com/watch?v=7nkKVyt0DsY

๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค 2022 ์„ค์น˜

๊ทผ๋ฐ ์›ƒ๊ธด ๊ฒŒ ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค 2022 ์„ค์น˜๋„ ์•ˆํ•ด๋†จ๋„ค?

๊ฐœ๋ณ„ ๊ตฌ์„ฑ ์š”์†Œ์—์„œ "C++๋ฅผ ์‚ฌ์šฉํ•œ ๋ฐ์Šคํฌํ†ฑ ๊ฐœ๋ฐœ"๊ณผ "C++๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒŒ์ž„ ๊ฐœ๋ฐœ" ์„ ํƒ

์„ค์น˜ ์ค‘...

SDL ์„ค์น˜

์Šคํฌ๋กค ์ญ‰์ญ‰ ๋‚ด๋ฆฌ๋ฉด~ SDL2-devel-2.24.0-VC.zip ๋‹ค์šด๋กœ๋“œ

๊ทธ๋ฆฌ๊ณ  ์ถ”๊ฐ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

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 ํด๋” ์ถ”๊ฐ€

  • ๊ตฌ์„ฑ ์†์„ฑ -> ๋ง์ปค -> ์ผ๋ฐ˜ -> ์ถ”๊ฐ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋””๋ ‰ํ† ๋ฆฌ

  • ๊ตฌ์„ฑ ์†์„ฑ -> ๋ง์ปค -> ์ž…๋ ฅ -> ์ถ”๊ฐ€ ์ข…์†์„ฑ

... ๋Š” ์•ˆ๋จ ;ใ…ก.,ใ…ก?ใ…‹

๋‹ค์Œ ๋ฒˆ์— ๋‹ค์‹œ ํ•ด๋ณด๋Š” ๊ฑธ๋กœ...

๋‹ค์šด๋กœ๋“œ ํŒŒ์ผ

  • ์œ„์— ๋‹ค์šด๋ฐ›์•„ ์„ค์น˜ํ•œ ํŒŒ์ผ๋“ค

VisualStudioSetup.exe
2.02MB
SDL2-devel-2.24.0-VC.zip
2.48MB
SDL_image-main.zip
9.58MB
SDL_mixer-main.zip
9.66MB

728x90
๋ฐ˜์‘ํ˜•