GP2X Got A Little C++/sdl Problem


Joined
Sep 14, 2005
Messages
458
Location
Sweden
Website
www.digitalawakening.net
Didn't seem to be much traffic at the other board I tried so I'm hoping for a reply here instead.

With Sol's tutorial as base I've started working on an image draw function, not that hard really. It's still very basic but I got an alpha color key coded in so I get transparency. Now the problem is when I want to use this function on another image. I really don't know how to do that so if someone could help me I would be quite happy. In case anyone wonders I'm using images the size of the screen at the moment, gonna make adjustments for that later. Getting this function to work as I want should be pretty much all I need to develop for GP2X, at least for now.

Code:
void drawimage(int x, int y)
{
  // Lock surface if needed
  if (SDL_MUSTLOCK(gFG))
    if (SDL_LockSurface(gFG) < 0) 
      return;

  int i, j;
  for (i = 0; i < WIDTH; i++)
  {
    int screenofs = x + (y + i) * PITCH;
    for (j = 0; j < WIDTH; j++)
    {
  if ( ((unsigned int*)gFG->pixels)[screenofs] != 0xffffff ) {
  	((unsigned int*)gScreen->pixels)[screenofs] =
    ((unsigned int*)gFG->pixels)[screenofs];
  }
      screenofs++;
    }
  }

  // Unlock if needed
    if (SDL_MUSTLOCK(gFG)) 
        SDL_UnlockSurface(gFG);
}
 
I do not fully understand what you mean.
This is a way to draw a picture.

Code:
void DrawImg(SDL_surface *screen, int x, int y)
{
   // destination rect
   SDL_Rect DRect;
   DRect.x = x;
   DRect.y = y;

   // blit the image to the screen
   SDL_BlitSurface(image,NULL,buffer,&DRect);

   return;
}

You do not need to lock the surface when your not drawing with pixels directly.
 
The "SDL_surface *screen" part in the function was my problem, I didn't realize I could do that but I managed to figure that out myself. By declaring a SDL_surface in the function like that makes it possible for me to call the function with another surface. Thanks anyway.

Didn't know I didn't need to lock the surface, thanks for that. And I also need to check out that blit function, was thinking of making my own, thanks.
 
Back
Top