How can access to the PRIMARY SURFACE ( screen ) with the SDL?

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.

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;

Try BitsPerPixel = 0;

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

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;

There is a good chance that your hardware doesn’t support 24 bits/pixel.
It may support 32 bits/pixel, which also gives you 24 bits of color, but
does not have the same pixel layout. If you hardware does not provide a
24 bits/pixel format, SDL will provide you a software surface that IS
24 bits/pixel. Of course, such a surface has to be copied to the real
hardware surface so you must call SDL_UpdateRects().
SDL will give you a software surface, even when you ask for a hardware
surface, if the hardware does not support the format you ask for.

		Bob PendletonOn Fri, 2003-04-04 at 08:36, jorge Scati wrote:
    // 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.

_______________________________________________ SDL mailing list
SDL at libsdl.org http://www.libsdl.org/mailman/listinfo/sdl

±-------------------------------------+