Jump to content
  • Advertisement
Sign in to follow this  

SDL - strange problem with drawing pixels on surface

This topic is 3017 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 = 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 = SDL_CreateRGBSurface(SDL_HWSURFACE, 7,7,32,255,255,255,0);

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

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

					if(mapzor[j][k])
						mapzor[j][k]--;
			}
		if(locked){
			SDL_UnlockSurface(particles_forms);
			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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!