Remove parameters dialog.
[SDL.s60v3.git] / symbian / test / sos_test / sdltest.cpp
blobb118837a22ebb9c1ba9a2d7bbe72fad8368c80d6
1 #include<sdl.h>
3 extern int Frames;
4 extern int Ticks;
5 extern int Done;
6 extern "C"
8 #include<GLES/gl.h>
12 void panic(char* aWhen)
14 fprintf(stderr, "SDL error: %s: %s\n", aWhen, SDL_GetError());
15 SDL_Quit();
16 exit(-1);
19 int main(int argc, char** argv)
21 if(SDL_Init(SDL_INIT_VIDEO) < 0 )
23 panic("init video");
26 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
27 if(modes == NULL)
29 panic("No available video modes");
32 int width = 160;
33 int height = 120;
34 if(modes != (SDL_Rect**) -1)
36 int mode_count = 0;
37 while(modes[mode_count] != NULL)
39 printf("Mode %d: %d %d", mode_count, modes[mode_count]->w, modes[mode_count]->h);
40 mode_count++;
42 width = modes[0]->w;
43 height = modes[0]->h;
46 width = 320;
47 height = 200;
49 const Uint32 videoflags = SDL_SWSURFACE | SDL_ANYFORMAT ;
50 const int bpp = 32; // full color
52 SDL_Surface* bmp = SDL_LoadBMP("ball.bmp");
54 if(bmp == NULL)
55 panic("image not found");
57 SDL_Surface* screen = SDL_SetVideoMode(width, height, bpp, videoflags);
59 SDL_Rect sourceRect;
60 sourceRect.x = 0;
61 sourceRect.y = 0;
62 sourceRect.w = bmp->w;
63 sourceRect.h = bmp->h;
65 int then = SDL_GetTicks();
68 SDL_Rect targetRect;
69 targetRect.x = (screen->w - bmp->w) / 2;
70 targetRect.y = (screen->h - bmp->h) / 2;
72 targetRect.w = bmp->w;
73 targetRect.h = bmp->h;
75 int upwards = 0;
76 int leftwards = 0;
78 int frames = 0;
80 while(!Done)
82 SDL_Event event;
83 while(SDL_PollEvent(&event))
85 switch(event.type)
87 case SDL_KEYDOWN:
88 case SDL_QUIT:
89 Done = 1;
90 break;
94 if(upwards)
96 targetRect.y--;
97 if(targetRect.y < 0)
99 upwards = 0;
100 targetRect.y = 0;
103 else
105 targetRect.y++;
106 if(targetRect.y + targetRect.h > screen->h)
108 upwards = 1;
109 targetRect.y = screen->h - targetRect.h;
113 if(leftwards)
115 targetRect.x--;
116 if(targetRect.x < 0)
118 leftwards = 0;
119 targetRect.x = 0;
122 else
124 targetRect.x++;
125 if(targetRect.x + targetRect.w > screen->w)
127 leftwards = 1;
128 targetRect.x = screen->w - targetRect.w;
132 SDL_BlitSurface(bmp, &sourceRect, screen, &targetRect);
133 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
134 ++frames;
137 int now = SDL_GetTicks();
138 Ticks = now - then;
139 Frames = frames;
140 SDL_FreeSurface(bmp);
141 SDL_FreeSurface(screen);
142 SDL_Quit();
143 return 0;