Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <SDL_image.h>
- int main(){
- // Setup everything
- SDL_Init(SDL_INIT_VIDEO);
- IMG_Init(IMG_INIT_PNG);
- SDL_Window *window = SDL_CreateWindow(
- "Get the cake",
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- 800,
- 600,
- SDL_WINDOW_OPENGL
- );
- // Issue goes away if I change the '0' in this line to SDL_RENDERER_SOFTWARE
- SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
- // Load cake image
- SDL_Surface * cake_img = IMG_Load("../assets/cake.png");
- SDL_Texture * cake = SDL_CreateTextureFromSurface(renderer, cake_img);
- SDL_Rect cake_rect;
- cake_rect.x = 100;
- cake_rect.y = 100;
- cake_rect.w = 64;
- cake_rect.h = 64;
- // Main event loop
- bool is_running = true;
- const Uint8* keys = SDL_GetKeyboardState(NULL);
- while (is_running){
- SDL_Event event;
- while (SDL_PollEvent(&event)){
- if (event.type == SDL_QUIT){
- is_running = false;
- }
- }
- SDL_RenderCopy(renderer, cake, NULL, &cake_rect);
- SDL_RenderPresent(renderer);
- }
- // Cleaning up
- SDL_DestroyTexture(cake);
- SDL_FreeSurface(cake_img);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- IMG_Quit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement