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-2011 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
34 /* The surface used as a display (in fact it is a software surface). */
35 SDL_Surface
*display
= NULL
;
38 /* Timer used for refreshing the display */
41 /* An event used for signaling that the timer was triggered. */
42 SDL_UserEvent timer_event
;
44 /* Values for color pixels in display format. */
45 GP_Pixel black
, white
;
47 Uint32
timer_callback(__attribute__((unused
)) Uint32 interval
,
48 __attribute__((unused
)) void * param
)
50 timer_event
.type
= SDL_USEREVENT
;
51 SDL_PushEvent((SDL_Event
*) &timer_event
);
55 double start_angle
= 0.0;
57 static int aa_flag
= 0;
58 static int pause_flag
= 0;
60 void redraw_screen(void)
64 int xcenter
= display
->w
/2;
65 int ycenter
= display
->h
/2;
67 SDL_LockSurface(display
);
68 GP_Fill(&context
, black
);
70 for (angle
= 0.0; angle
< 2*M_PI
; angle
+= 0.1) {
71 x
= (int) (display
->w
/2 * cos(start_angle
+ angle
));
72 y
= (int) (display
->h
/2 * sin(start_angle
+ angle
));
74 Uint8 r
= 127.0 + 127.0 * cos(start_angle
+ angle
);
75 Uint8 b
= 127.0 + 127.0 * sin(start_angle
+ angle
);
78 pixel
= GP_RGBToPixel(r
, 0, b
, context
.pixel_type
);
81 GP_LineAA_Raw(&context
, GP_FP_FROM_INT(xcenter
), GP_FP_FROM_INT(ycenter
),
82 GP_FP_FROM_INT(xcenter
+ x
), GP_FP_FROM_INT(ycenter
+ y
), pixel
);
84 GP_Line(&context
, xcenter
+ x
, ycenter
+ y
, xcenter
, ycenter
, pixel
);
85 GP_Line(&context
, xcenter
, ycenter
, xcenter
+ x
, ycenter
+ y
, pixel
);
90 // GP_HLineXYW(&context, 0, ycenter, display->w, white);
91 // GP_VLineXYH(&context, xcenter, 0, display->h, white);
93 SDL_UnlockSurface(display
);
100 while (SDL_WaitEvent(&event
) > 0) {
101 switch (event
.type
) {
110 if (start_angle
> 2*M_PI
) {
115 switch (event
.key
.keysym
.sym
) {
120 pause_flag
= !pause_flag
;
132 int main(int argc
, char **argv
)
135 retcode
= GP_SDL_VideoInit(&context
, 640, 480, argc
, argv
);
136 if (retcode
!= GP_ESUCCESS
) {
137 fprintf(stderr
, "Video initialization failed: %s\n",
138 GP_RetCodeName(retcode
));
142 display
= SDL_GetVideoSurface();
143 GP_SDL_ContextFromSurface(&context
, display
);
145 /* Load colors in display format */
146 black
= GP_ColorToContextPixel(GP_COL_BLACK
, &context
);
147 white
= GP_ColorToContextPixel(GP_COL_WHITE
, &context
);
149 /* Set up the refresh timer */
150 timer
= SDL_AddTimer(30, timer_callback
, NULL
);
152 fprintf(stderr
, "Could not set up timer: %s\n", SDL_GetError());
156 /* Enter the event loop */