I have a problem with the SDL in Windows . I need to access directly at the
primary surface for
write directly in video memory and that when It changes I can see the
results without that I must to call the
function UpdateRect(). I don?t know what is wrong in this code for access
to the primary surface ?
a) With the SDL :
SDL_Surface* screen; // equivale a la lpDDSurface
Uint32 videoflags;
videoflags = SDL_HWSURFACE ;
int sX=800;
int sY= 600;
int BitsPerPixel =24;
// Initialize SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
char caderr[256];
sprintf(caderr,"No se ha podido inicializar la SDL:
%s\n",SDL_GetError());
Write_Log(caderr);
return false;
}
// Accedo directamente a la superficie principal de visualizaci?n
if ( (screen=SDL_SetVideoMode(sX,sY,BitsPerPixel,videoflags)) ==
NULL )
{
char caderr[256];
sprintf(caderr,“Couldn’t set %dx%dx%d video mode: %s\n”,
sX, sY,
BitsPerPixel, SDL_GetError());
Write_Log(caderr);
return false;
}
/// Pruebas accediendo directamente al buffer de pantalla principal
if ( SDL_LockSurface(screen) < 0 )
{
char error[256];
sprintf(error, "Couldn't lock the display surface:
%s\n",SDL_GetError());
Write_Log(error);
return false;
}
SurfacePitch=screen->pitch;
lpSurface=screen->pixels;
SDL_UnlockSurface(screen);
b) With the DirectX directly :
HRESULT ddrval;
LPDIRECTDRAW lpdd;
DDSURFACEDESC ddsd;
DDCAPS DriverCaps;
LPDIRECTDRAWSURFACE lpDDSurface;
LPDIRECTDRAW lpDD;
lpDDSurface=NULL;
lpDD = NULL;
memset(&ddsd,0x00, sizeof(ddsd));
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if ( IDirectDraw_CreateSurface( lpdd, &ddsd, &lpDDSurface, NULL )
!=DD_OK)
{
Write_Log(“Erzeugen der Surface fehlerhaft”);
return(false);
}
ddrval = IDirectDrawSurface_Lock(lpDDSurface, NULL, &ddsd, 0, NULL);
ddrval = IDirectDrawSurface_Unlock(lpDDSurface, ddsd.lpSurface);
SurfacePitch=ddsd.lPitch;
lpSurface=ddsd.lpSurface;
It works correctly with the DirectX code and I the surface is visible all
the time. Is it possible with
the SDL ? How ? Can you help me please ?
Thanks a lot in advance .
Jorge.