1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
28 This example shows how to mix SDL with GFXprim.
36 #include <backends/GP_SDL_Pixmap.h>
41 static SDL_Surface
*display
= NULL
;
42 static GP_Pixmap pixmap
;
44 static GP_Pixel black_pixel
, darkgray_pixel
;
46 void redraw_screen(void)
48 SDL_LockSurface(display
);
50 GP_Fill(&pixmap
, black_pixel
);
52 GP_Text(&pixmap
, NULL
, W
/2, 20, GP_ALIGN_CENTER
| GP_VALIGN_BELOW
,
53 darkgray_pixel
, black_pixel
, "GFXprim SDL Demo");
55 GP_Line(&pixmap
, 0, 0, W
-1, H
-1, darkgray_pixel
);
56 GP_Line(&pixmap
, 0, H
-1, W
-1, 0, darkgray_pixel
);
58 SDL_UnlockSurface(display
);
65 while (SDL_WaitEvent(&event
) > 0) {
74 switch (event
.key
.keysym
.sym
) {
90 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
) != 0) {
91 fprintf(stderr
, "Could not initialize SDL: %s\n", SDL_GetError());
95 display
= SDL_SetVideoMode(W
, H
, 0, SDL_SWSURFACE
);
97 if (display
== NULL
) {
98 fprintf(stderr
, "Could not open display: %s\n", SDL_GetError());
103 GP_PixmapFromSDLSurface(&pixmap
, display
);
105 black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, &pixmap
);
106 darkgray_pixel
= GP_RGBToPixmapPixel(0x7f, 0x7f, 0x7f, &pixmap
);