[SDL] SDL Audio questions

Neil Bradley nb at synthcom.com
Sat Jul 27 14:55:01 PDT 2002

I am very confused, I still get full black screen, you must know that I manage to load bitmaps (and still don't manage to fill rects)
So I will give you the whoooole piece of code I want to use :)

but first :
> Try changing your SDL_BlitSurface(test,NULL,screen,&d); to 
> SDL_BlitSurface(test,NULL,screen,&r); saying as the rect r is set up with the 
> screen co-ordinates you want to blit to.

Yes that was a copy mistake :)

> Also, you may want to use the function SDL_MapRGB instead of supplying hex 
> values for colours.

> So instead of SDL_FillRect(test, NULL, 0xFFFFFF00);
> You would have SDL_FillRect(test, NULL, SDL_MapRBG(test->format,255,255,255));
> Please forgive any inaccuracies in my C, it's been a while :-)

Still don't see square..

But here is my code :

/*********** start ****************/
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>

int main(void)
	SDL_Surface *screen; //here the display window
	SDL_Surface *test; //a square
	SDL_Rect d; 	//for square destination position
	SDL_Event ev; //for futur events

	Uint32 rmask, gmask, bmask, amask;	
	#if SDL_BYTEORDER == SDL_BIG_ENDIAN //setup mask colors
	  rmask = 0xff000000;
	  gmask = 0x00ff0000;
	  bmask = 0x0000ff00;
	  amask = 0x000000ff;
	  rmask = 0x000000ff;
	  gmask = 0x0000ff00;
	  bmask = 0x00ff0000;
	  amask = 0xff000000;


		printf("** Video init.\n");
		printf("** No video.\n");
		printf("** Time init.\n");
		printf("** No timer.\n");

	//setup surfaces
	screen = SDL_SetVideoMode(800,600,16,SDL_HWSURFACE|SDL_DOUBLEBUF);
	test = SDL_CreateRGBSurface(SDL_SWSURFACE,100,100,16,rmask,gmask,bmask,amask);

	d.x = 150; //position where I want to blit the 'test' square into the screen
	d.y = 150;

	while(1) //main loop
		while (SDL_PollEvent(&ev))
			switch(ev.type) //events
				case SDL_QUIT:
					printf("** End\n");
					printf("** Unknown Event\n");
		// here we draw all
		SDL_FillRect(screen, NULL, SDL_MapRGB(Screen->format,0,0,0)); //to black
		SDL_FillRect(test, NULL, SDL_MapRGBA(test->format,255,255,255,0)); //to white

		SDL_BlitSurface(test,NULL,screen,&d); //blits test into screen
		//some people said that I should put a SOUCE RECTANGLE in second argument, but official
		// SDL documention says that if we pass NULL, whole source Surface is taken for blit.

/*********** end ****************/

Conclusion = why still a black screen with no white square ?

More information about the SDL mailing list