Sign in to follow this  
uzyszkodnik

SDL - strange problem with drawing pixels on surface

Recommended Posts

uzyszkodnik    100
Hello i've got a small problem with putting pixels directly on the surface. I've got a class constructor which is supposed to create bunch of red/yellow dots, instead of it he makes some gray ones. Here's its code
ParticleEngine::ParticleEngine(){
int mapzor[7][7] = {
		{000,000,251,252,251,000,000},
		{000,251,252,253,252,251,000},
		{251,252,253,254,253,252,251},
		{252,253,254,255,254,253,252},
		{251,252,253,254,253,252,251},
		{000,251,252,253,252,251,000},
		{000,000,251,252,251,000,000},

	};

	Uint32 colorz[256];
	int i,j,k; 
	Uint32 colorkey;

	for(i=0;i<128;i++)
		colorz[i] = SDL_MapRGB(screen->format, i*2,i,2);
	for(i=0;i<64;i++)
		colorz[i+128] = SDL_MapRGB(screen->format, 254,i+127,i+2); 
	for(i=0;i<66;i++)
		colorz[i+190]=SDL_MapRGB(screen->format, 254,i+190,i+65);

	int locked = 0;
	for(i=255;i>=0;i--){

		particles_forms[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 7,7,32,255,255,255,0);

		if(SDL_MUSTLOCK(particles_forms[i])){
			if(SDL_LockSurface(particles_forms[i])<=0)
				exit(1);		
			locked=1;
		}
		for(j=0;j<7;j++)
			for(k=0;k<7;k++){

					putpixel_rgb(particles_forms[i],j,k,colorz[mapzor[j][k]]);	

					if(mapzor[j][k])
						mapzor[j][k]--;
			}
		if(locked){
			SDL_UnlockSurface(particles_forms[i]);
			locked=0;
		}
	}

	dispersion = 3.14/4;
}
and the code of function putpixel_rgb
void putpixel_rgb(SDL_Surface *surf,int x, int y, Uint32 rgbzor){

   // Uint32 pixel= SDL_MapRGB(surf->format, R, G, B);
      Uint32 pixel = rgbzor;

    int bpp = surf->format->BytesPerPixel;
    /* Obliczamy adres pixela */
    Uint8 *p = (Uint8 *)surf->pixels + y * surf->pitch + x * bpp;

    switch(bpp)
    {
        case 1: //8-bit
            *p = pixel;
            break;

        case 2: //16-bit
            *(Uint16 *)p = pixel;
            break;

        case 3: //24-bit
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                p[0] = (pixel >> 16) & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = pixel & 0xff;
            } else {
                p[0] = pixel & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = (pixel >> 16) & 0xff;
            }
            break;

        case 4: //32-bit
            *(Uint32 *)p = pixel;
            break;
    }


}
As i've tested the putpixel_rgb on different targets with positive effects and i've checked values of the colorz table i think problem comes from lack of my knowledge about sdl. Thanks for any help. edit: a full code - http://www.sendspace.com/file/x7dl81 [Edited by - uzyszkodnik on February 17, 2010 12:57:04 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this