Created
July 16, 2012 15:08
-
-
Save Twinklebear/3123236 to your computer and use it in GitHub Desktop.
SDL Rendering methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//New rendering methods | |
//Now we use an SDL_Texture to use hardware accelerated rendering | |
//create window at 100, 100 with width 640 and height 480 and show it | |
SDL_Window *win = SDL_CreateWindow("Window", 100, 100, 640, 480, SDL_WINDOW_SHOWN); | |
//create a renderer that draws to win with hardware acceleration and vsync | |
SDL_Renderer *rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); | |
//Load our image and convert to texture | |
SDL_Surface *img = SDL_LoadBMP("image.bmp"); | |
//Create the texture, requires the rendering context so it knows what formatting we desire | |
SDL_Texture *tex = SDL_CreateTextureFromSurface(rend, img); | |
SDL_FreeSurface(img); | |
//Clear window | |
SDL_RenderClear(rend); | |
//Draw the texture the first NULL is the clip rect, the second NULL is the destination rect. Note that scaling w/h is supported! | |
//passing NULL destination rect will cause it to stretch the texture to fill screen | |
SDL_RenderCopy(rend, tex, NULL, NULL); | |
//Update screen | |
SDL_RenderPresent(rend); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Old SDL method of rendering | |
SDL_Surface *surf = SDL_LoadBMP("image.bmp"); | |
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE) //and etc.. | |
//draw with: | |
BlitSurface(surf, NULL, screen, NULL); | |
//And update screen | |
SDL_Flip(screen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment