Skip to content

Instantly share code, notes, and snippets.

@Twinklebear
Last active October 7, 2015 11:58
Show Gist options
  • Save Twinklebear/3161759 to your computer and use it in GitHub Desktop.
Save Twinklebear/3161759 to your computer and use it in GitHub Desktop.
//In main...
SDL_Texture *image = nullptr;
try {
image = LoadImage("../res/Lesson4/image.png");
}
catch (const std::runtime_error &e){
std::cout << e.what() << std::endl;
return 4;
}
int iW, iH;
SDL_QueryTexture(image, NULL, NULL, &iW, &iH);
int x = SCREEN_WIDTH / 2 - iW / 2;
int y = SCREEN_HEIGHT / 2 - iH / 2;
SDL_Event e;
bool quit = false;
while (!quit){
//Our main loop
//Event polling
while (SDL_PollEvent(&e)){
//If user closes he window
if (e.type == SDL_QUIT)
quit = true;
//If user presses any key
if (e.type == SDL_KEYDOWN)
quit = true;
//If user clicks the mouse
if (e.type == SDL_MOUSEBUTTONDOWN)
quit = true;
}
//Rendering
SDL_RenderClear(renderer);
//Draw the image
ApplySurface(x, y, image, renderer);
//Update the screen
SDL_RenderPresent(renderer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment