Skip to main content
gamedev.net
🔒 Locked

SDL help

Started by donbonifacio 1 reply 2.5k views
Original Post
donbonifacio
donbonifacio
hi, I have this problem with SDL. I want to create a small SDL_Surface, fill it with some color, then blit it to the screen surface. I do that, but when I use SDL_Flip the small surface is not shown... I have make a small example, could someone please tell me what I am doind wrong?
  
int main( int argc, char* argv[] )
{
	/* SDL init */
	if( SDL_Init ( SDL_INIT_VIDEO ) == -1 ) { 
		// error
	}
	atexit(SDL_Quit);

	SDL_Surface* s = SDL_SetVideoMode(200, 200, 0, SDL_SWSURFACE | SDL_DOUBLEBUF );


	/* Create new SDL_Surface (exemple from the docs) */
	Uint32 rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = 0xff000000;
	gmask = 0x00ff0000;
	bmask = 0x0000ff00;
	amask = 0x000000ff;
#else
	rmask = 0x000000ff;
	gmask = 0x0000ff00;
	bmask = 0x00ff0000;
	amask = 0xff000000;
#endif

    	SDL_Surface *p = SDL_CreateRGBSurface(SDL_SWSURFACE, 20, 20, 32, rmask, gmask, bmask, amask);
    
	/* fill the SDL_Surface - WHITE is defined with the white hexadecimal code */
	SDL_FillRect(p,NULL,WHITE);

	/* blit p to s */
	SDL_Rect temp = {10,10,200,200};
	SDL_BlitSurface(p,NULL,s,&temp);
	
	/* flip the screen surface */
	SDL_Flip(s);
	
	/* whait for click */
	SDL_Event event;
	while (true)
	{
		while(SDL_PollEvent(&event)) {
			if( event.type == SDL_QUIT )
				return 0;

			if( event.type == SDL_MOUSEBUTTONDOWN )
				return 0;
			
		}
	}
	return 0;
}
  
cone3d
cone3d
I mingled around with your code and the only way I could draw the box on the screen was by replacing
  
SDL_Surface *p = SDL_CreateRGBSurface(SDL_SWSURFACE, 20, 20, 32, rmask, gmask, bmask, amask);


with

  
unsigned char *data = new unsigned char[20*20*4];
for(int i=0;i<20*20*4;i++)
{
data[i]=255;
}

SDL_Surface *p = SDL_CreateRGBSurfaceFrom(data, 20, 20, 32, 20*4, rmask, gmask, bmask, amask);



---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.
---cone3dhttp://cone3d.gamedev.netMy software never has any bugs - it just generates random features

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.