OT - SDL and shapes not showing

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 }

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 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

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?

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:

Code update:

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 SDL_UpdateRect(screen, 0, 0, 0, 0);
77
78
79
80 return 0;
81 }

As far as I can tell, the same results. I still don’t see the box…On Mon, 2007-11-12 at 19:52 -0600, Matthew Johnson wrote:

On Nov 12, 2007 5:16 PM, Michael Sullivan wrote:

Michael Sullivan wrote:

[snip]

[snip] 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:

Just guessing. Why don’t you add a delay call somewhere after the
call to the second screen update?> On Mon, 2007-11-12 at 19:52 -0600, Matthew Johnson wrote:

On Nov 12, 2007 5:16 PM, Michael Sullivan wrote:

Code update:
michael at camille ourrpg $ nl battle.c
[snip]


Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

Totally a shot in the dark but for your color instead of 0xFFFFFF have you
tried 0xFFFFFFFF?

There may be an alpha byte that is getting set to 0 (completely
transparent?) by your color declaration (:> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of Michael Sullivan
Sent: Monday, November 12, 2007 3:16 PM
To: SDL at lists.libsdl.org
Subject: [SDL] OT - SDL and shapes not showing

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