i’m sorry my english is not really good enough, so i’m learning sdl right now, and i need some help, maybe it’s simple problem but the problem it’s make me frustated
this is my code :
#include
#include <SDL.h>
#include <stdio.h>
using namespace std;
//screen dimension constant
const int SCREEN_HEIGHT = 480;
const int SCREEN_WIDTH = 640;
//The window we’ll be rendering to
SDL_Window* gWindow = NULL;
//The image we will load and show on the screen
SDL_Surface* gXOut = NULL;
//The surface contained by the window
SDL_Surface* gScreenSurface = NULL;
//Starts up SDL and creates window
bool init();
//load media
bool loadMedia();
//Frees media and shuts down SDL
bool close();
int main(int argc, char* argv[])
{
//Start up SDL and create window
if(!init())
{
cout << “can’t inizialize\n”;
}
else
{
//Load media
if(!loadMedia())
{
cout << “can’t load the media\n”;
}
else
{
//Main loop flag
bool quit= false;
//Event handler
SDL_Event e;
//While application is running
while(!quit)
{
//Handle events on queue
while(SDL_PollEvent( &e ) != 0)
{
//User requests quit
if(e.type == SDL_QUIT)
{
quit = true;
}
}
//Apply the image
SDL_BlitSurface(gXOut, NULL, gScreenSurface, NULL);
//Update the surface
SDL_UpdateWindowSurface(gWindow);
}
}
}
//Free resources and close SDL
close();
}
bool init()
{
//Initialization flag
bool success = true;
//Initialization flag
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << "SDL can't initialize\n" << SDL_GetError();
success = false;
}
else
{
//Create window
gWindow = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOWEVENT_SHOWN);
if(gWindow == NULL)
{
cout << "SDL can't make window\n" << SDL_GetError();
success = false;
}
else
{
//Get window surface
gScreenSurface = SDL_GetWindowSurface(gWindow);
}
}
return success;
}
bool loadMedia()
{
//Loading success flag
bool success = true;
//Load splash image
gXOut = SDL_LoadBMP("test_7/hqdefault");
if(gXOut == NULL)
{
cout << "can't load the media! error \n" << "test_7/img/hqdefault " << SDL_GetError();
success = false;
}
return success;
}
bool close()
{
//Deallocate surface
SDL_FreeSurface(gXOut);
gXOut = NULL;
//Destroy window
SDL_DestroyWindow(gWindow);
gWindow = NULL;
//Quit SDL subsystem
SDL_Quit();
}
i dont know why, the picture didn’t show