The reason you're getting that compiler error is because SDL_DisplayFormat
no longer exist in SDL-2.0.
After looking at the SDL wiki doc it appears SDL_DisplayFormat
from SDL-1.2 has been replaced by SDL_ConvertSurfaceFormat
in SDL-2.0.
Question
Compiler doesn't return missing SDL.h, but rather that SDL_DisplayFormat is not declared in scope of a class member function located on a different header even though I have it initialized in main.
SDL_Surface *SpriteLoad::Load(char *File)
{
SDL_Surface *temp = NULL;
SDL_Surface *opt = NULL;
if ((temp = IMG_Load(File)) == NULL)
{
return NULL;
}
opt = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
return opt;
}
Where my main inits SDL through a class and member function:
int main (int args, char *argc[])
{
bool quit = false;
OnRun Game; // Class that init's SDL
Window TestWin;
GlobalTimer fps;
TestWin.Debug();
I'm able to create a window using SDL_Window using that Class and also use SDL_GetTick.
EDIT: Headers used for Sprite::Load are currently SDL, SDL_image, SDL_ttf, and SDL_mixer pulled and built from the mercurial repo. I do not think it's a linking error though
Solution
The reason you're getting that compiler error is because SDL_DisplayFormat
no longer exist in SDL-2.0.
After looking at the SDL wiki doc it appears SDL_DisplayFormat
from SDL-1.2 has been replaced by SDL_ConvertSurfaceFormat
in SDL-2.0.
OTHER TIPS
I would rewrite your code as follows for SDL 2.0;
SDL_Surface *SpriteLoad::Load(SDL_Window *window, char *File)
{
SDL_Surface *temp = NULL;
SDL_Surface *opt = NULL;
if ((temp = IMG_Load(File)) == NULL)
{
return NULL;
}
// If the window wasn't created yet, just return the texture
if(window == NULL) return temp;
opt = SDL_ConvertSurfaceFormat(temp, SDL_GetWindowPixelFormat(window), 0);
SDL_FreeSurface(temp);
return opt;
}
In my own code I return the image unoptimized if there is no window created yet (I sometimes use this for a splash screen before the window). But you could change this so that it free's temp and returns NULL if that is important for you, perhaps with a warning to create a window first.