I'm SDL and OpenGL in C++. In MVSC++ if that matters at all.
Here's what I'm trying to do: I want to take an image file and load it in as a SDL_Surface*. That part I've got down. The last part I want to do is take that SDL_Surface* and create an OpenGL texture from it. That part I've got working too.
The middle part is where I'm having trouble. I want to take the original SDL_Surface* and create a new, blank surface with dimensions that are a power of two; then, I'll blit the original surface to this new one. It's just giving me black though; I suspect that either the blit isn't happening, or that OpenGL can't generate a texture from the resulting surface.
Here's the code that's actually giving me trouble. And just to clarify, it works fine if I skip this part, but then I can only use textures that are a power of two.
SDL_Surface* padImage(SDL_Surface* image) {
if (!image) {
return NULL;
}
int width = gfx::powerOfTwo(image->w);
int height = gfx::powerOfTwo(image->h);
SDL_Surface* padded = SDL_CreateRGBSurface(image->flags,
width,
height,
image->format->BitsPerPixel,
image->format->Rmask,
image->format->Gmask,
image->format->Bmask,
image->format->Amask);
if (!padded) {
return NULL;
}
SDL_BlitSurface(image, NULL, padded, NULL);
return padded;
};
From my reading, I've come to understand that using SDL_BlitSurface() is a no-no when using OpenGL. So I guess I want to know how to properly blit one SDL_Surface* onto another in an OpenGL context.
I know that I can use an OpenGL function to generate a texture from a non-power-of-two dimensioned surface, but it makes ugly, blurry textures.
SDL_BlitSurfaceto see whether it worked or not? And are you sure you don't wantSDL_BlitScaled? - yzt