Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/the-eternalshop/learn-sdl2-in-1-hour-easy
An @eternalxlks-styled tutorial on learning SDL2, complete with no descriptions!
https://github.com/the-eternalshop/learn-sdl2-in-1-hour-easy
c-lang c-language c-plus-plus c-plus-plus-language c-programming-language cplusplus cpp learn-sdl learn-sdl2 sdl sdl2
Last synced: 10 days ago
JSON representation
An @eternalxlks-styled tutorial on learning SDL2, complete with no descriptions!
- Host: GitHub
- URL: https://github.com/the-eternalshop/learn-sdl2-in-1-hour-easy
- Owner: The-EternalShop
- Created: 2024-11-25T03:24:13.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T17:21:12.000Z (about 2 months ago)
- Last Synced: 2024-12-16T18:26:41.911Z (about 2 months ago)
- Topics: c-lang, c-language, c-plus-plus, c-plus-plus-language, c-programming-language, cplusplus, cpp, learn-sdl, learn-sdl2, sdl, sdl2
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Learn SDL2 in 1 Hour!
Wanna learn SDL2? You can learn it here!
## Step 1: Set Up Your Build Environment
Install SDL2 and, um, probably SDL_image if you're unlucky, and also use brew and the official installation for maximum compatibility, not like that will do anything bad (forshadowing). Then copy and paste this code into a file called Makefile or else:
```Makefile
main: $(wildcard *.cpp)
g++ $(wildcard *.cpp) -o main -F/Library/Frameworks -framework SDL2 -std=c++17 -Wl,-rpath,/Library/Frameworks
```## Step 2: Make Sure You're Running This On A Mac
If you are running this on a non-Mac, then, um, bad things will happen. Also try to replicate step 1 exactly, if you get my drift.
## Step 3: Copy the File
Should be the easiest step; this is just as comprehendable as, um, Spanish?
```cpp
#include
#includeusing namespace std;
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cerr << "Failed to initialize SDL: " << SDL_GetError() << endl;
return -1;
}SDL_Window* window = SDL_CreateWindow(
"Lego Island 2D Clone",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_SHOWN
);if (!window) {
cerr << "Failed to create window: " << SDL_GetError() << endl;
SDL_Quit();
return -1;
}SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
cerr << "Failed to create renderer: " << SDL_GetError() << endl;
SDL_DestroyWindow(window);
SDL_Quit();
return -1;
}bool running = true;
SDL_Event event;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderClear(renderer);SDL_RenderPresent(renderer);
SDL_Delay(16);
}SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
```## Step 4: Run This Command
`make; ./main` If this fails, good luck! Ok bye for now!