Switch to renderer
This commit is contained in:
parent
b0030425a4
commit
868922c68e
18
main.cpp
18
main.cpp
@ -42,14 +42,15 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
SDL_Renderer* renderer =
|
SDL_Renderer* renderer =
|
||||||
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
SDL_SetRenderDrawColor(renderer, 130, 163, 255, 1);
|
||||||
|
|
||||||
|
|
||||||
SDL_Surface* imageSurface = IMG_Load("font.png");
|
SDL_Surface* fontSurface = IMG_Load("font.png");
|
||||||
if (imageSurface == NULL) {
|
if (fontSurface == NULL) {
|
||||||
cout << "Could not find spritesheet" << endl;
|
cout << "Could not find spritesheet" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
SDL_Texture* fontTexture = SDL_CreateTextureFromSurface(renderer, fontSurface);
|
||||||
// SDL_Surface* screenSurface = NULL;
|
// SDL_Surface* screenSurface = NULL;
|
||||||
// //Get window surface
|
// //Get window surface
|
||||||
// screenSurface = SDL_GetWindowSurface( window );
|
// screenSurface = SDL_GetWindowSurface( window );
|
||||||
@ -96,24 +97,27 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
dstrect.x = SCREEN_WIDTH/2 - 40;
|
dstrect.x = SCREEN_WIDTH/2 - 40;
|
||||||
dstrect.y = SCREEN_HEIGHT/2 - 40;
|
dstrect.y = SCREEN_HEIGHT/2 - 40;
|
||||||
dstrect.w = 10;
|
dstrect.w = 100;
|
||||||
dstrect.h = 10;
|
dstrect.h = 100;
|
||||||
|
|
||||||
// SDL_BlitSurface(imageSurface, &srcrect, screenSurface, &dstrect);
|
// SDL_BlitSurface(imageSurface, &srcrect, screenSurface, &dstrect);
|
||||||
|
|
||||||
//Update the surface
|
//Update the surface
|
||||||
// SDL_UpdateWindowSurface( window );
|
// SDL_UpdateWindowSurface( window );
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, 130, 163, 255, 1);
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer, fontTexture, &srcrect, &dstrect);
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Hack to get window to stay up
|
//Hack to get window to stay up
|
||||||
// SDL_FreeSurface(screenSurface);
|
// SDL_FreeSurface(screenSurface);
|
||||||
SDL_FreeSurface(imageSurface);
|
SDL_FreeSurface(fontSurface);
|
||||||
|
SDL_DestroyTexture(fontTexture);
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow( window );
|
SDL_DestroyWindow( window );
|
||||||
|
|
||||||
//Quit SDL subsystems
|
//Quit SDL subsystems
|
||||||
|
Loading…
x
Reference in New Issue
Block a user