cranberry
Posts: 10
Joined: Wed Mar 13, 2013 4:37 pm

SDL: image and drawing something

Thu Aug 22, 2013 8:40 pm

I am reloading image time by time to screen SDL_Surface. Then I draw manually some lines to same screen SDL_Surface. The problem is that lines should be top of image, if I reload a new image, lines are hidden. What would be fastest way to refresh lines? Can I use somehow second surface?

The code is something like this:

// Init
screen = SDL_SetVideoMode( systemX, systemY, bpp, SDL_SWSURFACE );

//Loading image
SDL_BlitSurface(imageSurf, NULL, screen, &offset);
SDL_Flip( screen );

// Drawing lines call setPixel function and then update screen
char *position = (char *)screen->pixels;
position += ( screen->pitch * y );
position += ( screen->format->BytesPerPixel * x );
memcpy ( position , &color , screen->format->BytesPerPixel );
...
SDL_Flip( screen );

ramstrong
Posts: 36
Joined: Thu Aug 15, 2013 11:14 pm
Contact: Website

Re: SDL: image and drawing something

Thu Aug 22, 2013 8:52 pm

Looks like you have an extra flip. You have image-flip-lines-flip, where you should have image-lines-flip.
Raspberry Pi Journal: http://simpletongeek.blogspot.com/p/raspberry-pi-journal-directory_4.html

theArtist
Posts: 7
Joined: Tue Aug 27, 2013 9:02 am

Re: SDL: image and drawing something

Fri Sep 06, 2013 5:30 am

You do not need a second surface.

You could do this:

Code: Select all

//First write the image onto the screen

SDL_BlitSurface(imageSurf, NULL, screen, &offset);

// Drawing lines call setPixel function to write over the screen which already contains the image
char *position = (char *)screen->pixels;
position += ( screen->pitch * y );
position += ( screen->format->BytesPerPixel * x );
memcpy ( position , &color , screen->format->BytesPerPixel );

//Then finally refresh the screen
SDL_Flip(screen);

Return to “Graphics programming”