Original Post
Hi all I'm able to draw pixels in many ways and get pixel values and place them somewhere on the screen surface but when It happens the left over pixel is still there and I was hoping someone could show me code and explain how to remove it from the screen surface here is my code to draw and to get pixels :
any tips and suggestions are also welcome although this was intended as a test case not a perfect example of coding grammatically and correctly per-say of my ability.
Thanks for anyone who reads this .
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <math.h>
#undef main
int y = 10;
int x = 10;
int x2 = 40;
int y2 = 40;
SDL_Surface *Screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE),
*Image;
void pixeldraw(int x, int y , int color)
{
unsigned int *ptr = static_cast <unsigned int *> (Screen->pixels);
int offset = y * (Screen->pitch / sizeof(unsigned int));
ptr[offset + x] = color;
}
unsigned int pixelget(int x, int y)
{
unsigned int *ptr = static_cast <unsigned int *> (Screen->pixels);
int offset = y * (Screen->pitch / sizeof(unsigned int));
return ptr[offset + x];
}
int main(int argc , char *argv[])
{
SDL_WM_SetCaption("Image Pixel Manipulation", "PM");
Image = IMG_Load("image.png");
//unsigned int *src0 = (unsigned int *) Image->pixels + y * //Image->pitch;
SDL_FillRect(Screen,NULL,(0,0,0));
pixeldraw(10, 10, 0x0000FF);
unsigned int color = pixelget(10, 10);
pixeldraw(x2,y2, color);
printf("%08x\n", color);
//unsigned int *pixels = (unsigned int*) Screen->pixels;
//unsigned int color = pixels[y * (Screen->pitch / /sizeof(unsigned int)) + x];
// pixels[y2 * (Screen->pitch / sizeof(unsigned int) + x2] = color;
//src0[1] = 0;
bool done = false;
SDL_Event event;
while(!done)
{
//SDL_BlitSurface(Image,NULL,Screen,NULL);
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
return 0;
break;
}
}
SDL_Flip(Screen);
}
return 0;
}
any tips and suggestions are also welcome although this was intended as a test case not a perfect example of coding grammatically and correctly per-say of my ability.
Thanks for anyone who reads this .