Problems with X video memory protect

Hello Again !!!

I have another little problem with graphics (all SDL :slight_smile: )

First, three questions:
When you alloc a new suface, does it has all pointers allocated or
you must alloc it? (Ex. new_suface->pixels)
And when it is allocated, it points directly to the video mem or
not… (If the answer is yes, then I can modify the content
directly - framebuffer - with lock or unlock if necesary, correct?)

If the screen has different pixel format SDL does conversion, but

when and how, because now I use the imlib lib so it can
do some of the transformations. Is this correct too?

Can I handle a 24 bit surface with a screen depth of 32 copying a 24

bit pix on the 24 bit surface and waiting that it will show in the 32
bit screen?

(long, long question, sorry)

And then my program…

I breaks with a video memory protecting message when I try to put

the raw pix on the surface…

The init

screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
// The main surface (others for double and

// triple buffer)

if ( screen == NULL ) {
cout << stderr << "No puedo inicializar el modo grafico: " <<
SDL_GetError(); // Can’t init
return;
}

if ( SDL_MUSTLOCK(screen) )
cout << “Debe ser bloqueada”; // -> This happen
else
cout << “No debe ser bloqueada”;
cout << flush;

and the conflict:

disp=XOpenDisplay(NULL);
/* Immediately afterwards Intitialise Imlib */
ID=Imlib_init(disp);
im=Imlib_load_image(ID,“Graficos/Portada.png”); //the pix

Imlib_render(ID,im,800,600);
//This convert it to 24 bit per pixel, OK?

cout << “\n Graficos/Portada.png abierto con exit y es png” <<
fflush; // Ack message

SDL_LockSurface(Main_status.screen); // Is this correct?
Main_status is a object that has the screen pointer
// of the
initialization

nueva_sur = SDL_AllocSurface
(SDL_SWSURFACE,800,600,24,0xFF0000,0xFF00,0xFF,0); // 24 bit surf
memmove(Main_status.screen->pixels,im->rgb_data,80060024);
// move the data
// With 24 bits on the screen surface happens the same

//SDL_BlitSurface(nueva_sur,NULL,Main_status.screen,NULL);
SDL_Delay(5000);
SDL_UnlockSurface(Main_status.screen);
SDL_FreeSurface(nueva_sur);

cout << "\n OK : " << fflush;

Thats all
Hope someone can help me…

Hello Again !!!

I have another little problem with graphics (all SDL :slight_smile: )

First, three questions:
When you alloc a new suface, does it has all pointers allocated or
you must alloc it? (Ex. new_suface->pixels)

If you pass in a width and height, it allocates the surface memory.

If you pass in zero width and height, it leaves the surface memory
NULL for you to fill. Note that it does set up some internal blit
information, so you do need to call SDL_AllocSurface() to create a
surface.

If you create a zero size SDL surface, you can set the pixels yourself,
but you need to set the following information:

surface->pixels - surface memory pointer
surface->w - width in pixels
surface->h - height in pixels
surface->pitch - bytes per scanline

And when it is allocated, it points directly to the video mem or

not… (If the answer is yes, then I can modify the content
directly - framebuffer - with lock or unlock if necesary, correct?)

Usually not.

If the screen has different pixel format SDL does conversion, but

when and how, because now I use the imlib lib so it can
do some of the transformations. Is this correct too?

SDL does conversion during the blit. Imlib is too slow for real-time
pixel conversion, in my experience.

Can I handle a 24 bit surface with a screen depth of 32 copying a 24

bit pix on the 24 bit surface and waiting that it will show in the 32
bit screen?

Yes, but it’s much faster to use 32-bits all the way. 16-bit is even faster.

I breaks with a video memory protecting message when I try to put

the raw pix on the surface…

It sounds like you are writing past the end of the surface memory.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec