Garbled image when blitting texture to window

This code produces a 640x480 window with a garbled image neatly centred.
I suspect the problem lies with SDL_CreateTextureFromSurface.
I’m using SDL 1.3 svn 4520 on OpenSUSE Linux.

Anyone know how to get this working?

#include “SDLpp2/SDLpp.hpp”
#include

int main() {
try {
SDL::SDL instance(SDL_INIT_EVERYTHING);
SDL_WindowID window = SDL_CreateWindow(
“Blah”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_SHOWN);
if (window == 0)
throw SDL::Error();
if (SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED) != 0)
throw SDL::Error(“Unable to create renderer”);
if (SDL_SelectRenderer(window) != 0)
throw SDL::Error(“No renderer”);

SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_BLEND);

SDL::Surface bmp(SDL_LoadBMP("somebitmap.bmp"));
if (bmp == 0)
    throw SDL::Error();

SDL_TextureID tex = SDL_CreateTextureFromSurface(0, bmp);
if (tex == 0)
    throw SDL::Error();
SDL_Rect r = {(640 - bmp->w) / 2, (480 - bmp->h) / 2, bmp->w, bmp->h};
if (SDL_RenderCopy(tex, 0, &r) != 0)
    throw SDL::Error();
SDL_RenderPresent();

while (1)	{
    SDL_Event event;
    while (SDL_PollEvent(&event))	{
	switch (event.type)	{
	    case SDL_KEYDOWN:
	    case SDL_QUIT:
		return 0;
	}
    }
}
} catch (SDL::Error e)	{
std::cerr << std::endl << "SDL Error:  " << e.what() << std::endl;
}
return 1;

}

-------------- next part --------------
A non-text attachment was scrubbed…
Name: somebitmap.bmp
Type: image/bmp
Size: 5174 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090527/12a2bfcb/attachment.bin