[SDL] OT - SDL and shapes not showing

Matthew Johnson levifiction at gmail.com
Mon Nov 12 17:52:46 PST 2007


I could be way off as I'm still learning the basics, but aren't you
suppose to do SDL_UpdateRect() one last time to show any new changes
made to the screen surface?  At the moment you update the drawing of
the images but you then draw a line without updating the screen at
all.  Is SDL_gfx suppose to update the screen for you?


On Nov 12, 2007 5:16 PM, Michael Sullivan <michael at espersunited.com> wrote:
> My project involves SDL.  I'm completely new to SDL.  I couldn't find in
> my book how to do shapes and lines, so I did a search on Google.  I
> found this site:  http://www.ferzkopp.net/joomla/content/view/19/14/ .
> I downloaded and built their SDL_gfx package, then updated my code.  I
> needed a function that could draw white lines.  I tried their hlineColor
> function several times and could never see anything.  Then I tried their
> boxColor function and still can't see anything.  Everything seems to
> build correctly, but when I run it, the filled box doesn't show up.  Am
> I doing something wrong?  Is it there, but going away so quickly I don't
> see it?  Here's my code:
>
> michael at camille ourrpg $ nl battle.c
>      1  #include <stdio.h>
>      2  #include <SDL/SDL.h>
>      3  #include <SDL/SDL_image.h>
>      4  #include <SDL/SDL_gfxPrimitives.h>
>      5  #include <stdlib.h>
>      6  #include "battle.h"
>      7
>      8
>      9  void loadImage(int index, char* filename)
>     10  {
>     11     image[index] = IMG_Load(filename);
>     12     if (image == NULL)
>     13     {
>     14        printf("Unable to load image %s:  %s\n", filename,
> SDL_GetError());
>     15     }
>     16
>     17     colorkey = SDL_MapRGB(image[index]->format, 0, 255, 0);
>     18     SDL_SetColorKey(image[index], SDL_SRCCOLORKEY, colorkey);
>     19
>     20     src[index].x = 0;
>     21     src[index].y = 0;
>     22     src[index].w = image[index]->w;
>     23     src[index].h = image[index]->h;
>     24
>     25     dest[index].x = 600;
>     26     dest[index].y = index * 100;
>     27     dest[index].w = image[index]->w;
>     28     dest[index].h = image[index]->h;
>     29  }
>     30
>     31  int main()
>     32  {
>     33     if (SDL_Init(SDL_INIT_VIDEO) != 0)
>     34     {
>     35        printf("Unable to initialize SDL:  %s\n", SDL_GetError());
>     36        return 1;
>     37     }
>     38     atexit(SDL_Quit);
>     39
>     40     screen =  SDL_SetVideoMode(1000, 675, 16, 0);
>     41     if (screen == NULL)
>     42     {
>     43        printf("Unable to set video mode:  %s\n", SDL_GetError());
>     44        return 1;
>     45     }
>     46
>     47
>     48
>     49
>     50     int i;
>     51     i = 0;
>     52     /*Draw the allies*/
>     53     loadImage(i++, "ffight.gif");
>     54     loadImage(i++, "tfight.gif");
>     55     loadImage(i++, "wmfight.gif");
>     56     loadImage(i++, "bmfight.gif");
>     57
>     58     for (i = 0; i < 4; i++)
>     59     {
>     60        SDL_BlitSurface(image[i], &src[i], screen, &dest[i]);
>     61     }
>     62
>     63     /*Draw the enemies*/
>     64
>     65     SDL_UpdateRect(screen, 0, 0, 0, 0);
>     66
>     67     SDL_Delay(3000);
>     68
>     69     for (i = 0; i < 4; i++)
>     70     {
>     71        SDL_FreeSurface(image[i]);
>     72     }
>     73
>     74     /*Draw the battle screen lines*/
>     75     i = boxColor(screen, 0, 0, 600, 600, 0xFFFFFF);
>     76
>     77     SDL_Delay(3000);
>     78
>     79
>     80     return 0;
>     81  }
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>


More information about the SDL mailing list