1
votes

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.

1
What version of SDL are you using: 2 or 1.2? Have you checked the return value of SDL_BlitSurface to see whether it worked or not? And are you sure you don't want SDL_BlitScaled? - yzt
Why all that effort with making a power-of-2 sized image? Ever since OpenGL-2 arbitrary sized images are supported for textures just fine. - datenwolf
Well shoot. All my OpenGL knowledge is based off of some older tutorials, and I guess I just haven't read enough about, or experimented enough with, OpenGL-2. - Seymore Glass

1 Answers

0
votes

Welp, I didn't need to do any of that. As datenwolf pointed out, power of two dimensioned images aren't necessary. If I need to do anything like bliting one surface onto another, I'll do it with a Frame Buffer Object and textures instead.