Skip to content

Instantly share code, notes, and snippets.

@Twinklebear
Created July 19, 2012 00:17
Show Gist options
  • Save Twinklebear/3139888 to your computer and use it in GitHub Desktop.
Save Twinklebear/3139888 to your computer and use it in GitHub Desktop.
int main(int argc, char** argv){
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
std::cout << SDL_GetError() << std::endl;
return 1;
}
SDL_Window *win = nullptr;
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (win == nullptr){
std::cout << SDL_GetError() << std::endl;
return 1;
}
SDL_Renderer *ren = nullptr;
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == nullptr){
std::cout << SDL_GetError() << std::endl;
return 1;
}
SDL_Surface *bmp = nullptr;
bmp = SDL_LoadBMP("../res/Lesson1/hello.bmp");
if (bmp == nullptr){
std::cout << SDL_GetError() << std::endl;
return 1;
}
SDL_Texture *tex = nullptr;
tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);
SDL_Delay(2000);
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment