Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Cave-Crawler/image_loader.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (44 sloc)
1.31 KB
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
#include <iostream> | |
#include <SDL_image.h> | |
#include <SDL.h> | |
int main(int argc, char *argv[]) | |
{ | |
SDL_Surface* myImage = NULL; | |
SDL_Surface* imageWindow = NULL; | |
// Test if make sure SDL is initialised | |
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) | |
{ | |
std::cout << "SDL could not initialise: " << SDL_GetError() << std::endl; | |
} | |
SDL_Window *window = SDL_CreateWindow( "Title Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 400, SDL_WINDOW_SHOWN); | |
if(window == NULL) | |
{ | |
std::cout << "Window failed to be created: " << SDL_GetError( ) << std::endl; | |
return 1; | |
} | |
if( !(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) ) | |
{ | |
std::cout << "Could not Initialise IMG: " << IMG_GetError( ) << std::endl; | |
return 1; | |
} | |
SDL_Event loadIMG; | |
myImage = IMG_Load(CaveArt.png); | |
while(1) | |
{ | |
// While the window event is happening, it is checking to see if the user quits. | |
if(SDL_PollEvent(&loadIMG)) | |
{ | |
if(loadIMG.type == SDL_QUIT) | |
break; | |
} | |
//This is a drawing method | |
SDL_BlitSurface(myImage , NULL, imageWindow , NULL); | |
SDL_updateWindowSurface (window); | |
} | |
SDL_FreeSurface(myImage); | |
SDL_FreeSurface(imageWindow); | |
myImage = NULL; | |
imageWindow = NULL; | |
SDL_DestroyWindow(window); | |
return EXIT_SUCCESS; | |
} | |