int LoadTexture2D(const char* filename)
{
SDL_Surface* surface = IMG_Load(filename);
if (!surface)
{
errorlevel = 2;
return -1;
}
if ((surface->w & (surface->w - 1)) != 0)
++warnings;
if ((surface->h & (surface->h - 1)) != 0)
++warnings;
printf("%d\n", surface->format->BitsPerPixel);
numOfColors = surface->format->BytesPerPixel;
printf("%d\n", numOfColors);
switch (numOfColors)
{
case 3:
if (surface->format->Rmask == 0x000000ff)
textureFormat = GL_RGB;
else
textureFormat = GL_BGR;
break;
case 4:
if (surface->format->Rmask == 0x000000ff)
textureFormat = GL_RGBA;
else
textureFormat = GL_BGRA;
break;
default:;
++warnings;
errorlevel = 2;
return -1;
break;
}
Width = surface->w;
Height = surface->h;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, numOfColors, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
SDL_FreeSurface(surface);
return 0;
}
In case you're wondering, this function is inside a class and so are the variables that it's using. So what's the problem, is it just that this function is outdated for SDL 2.0? Should I load an OpenGL texture some other way?