Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main(int arc, char ** argv)
- {
- SDL_Window* pWindow = NULL;
- SDL_Event event;
- SDL_Renderer *pRenderer = NULL;
- SDL_Texture* pTexture = NULL;
- SDL_Surface* pSprite = NULL;
- SDL_Rect dest;
- bool cont = true;
- int CurrentTime = 0, seconds = 0, PassedTime = 0;
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
- }
- else
- {
- pWindow = SDL_CreateWindow("SDL2 Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
- }
- pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
- if (pRenderer)
- {
- pSprite = SDL_LoadBMP("resource/deck/grid.bmp");
- if (pSprite)
- {
- pTexture = SDL_CreateTextureFromSurface(pRenderer, pSprite);
- if (pTexture)
- {
- dest = {0, 0, 800, 600}; //{800, 600, pSprite->w, pSprite->h }; //{ 640 / 2 - pSprite->w / 2,480 / 2 - pSprite->h / 2, pSprite->w, pSprite->h };
- SDL_RenderCopy(pRenderer, pTexture, NULL, &dest);
- SDL_RenderPresent(pRenderer);
- }
- else
- {
- cout << "Couldn't display image : " << SDL_GetError() << endl;
- }
- }
- else
- {
- cout << "Sprite loading error : " << SDL_GetError() <<endl;
- }
- }
- else
- {
- cout << "Couldn't create renderer : " << SDL_GetError() << endl;
- }
- while (cont != 0)
- {
- while (SDL_PollEvent(&event))
- {
- //SDL_FlushEvent(SDL_QUIT);
- switch (event.type)
- {
- case SDL_KEYDOWN:
- if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
- {
- cout << "Quit" << endl;
- cont = 0;
- }
- break;
- //case SDL_WINDOWEVENT:
- case SDL_QUIT:
- cont = false;
- break;
- default:
- break;
- }
- }
- SDL_RenderClear(pRenderer);
- SDL_RenderCopy(pRenderer, pTexture, NULL, &dest);
- SDL_RenderPresent(pRenderer);
- CurrentTime = SDL_GetTicks();
- if (CurrentTime - PassedTime > 1000)
- {
- seconds++;
- cout << seconds << endl;
- PassedTime = CurrentTime;
- }
- }
- SDL_DestroyTexture(pTexture);
- SDL_DestroyRenderer(pRenderer);
- SDL_FreeSurface(pSprite);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement