|
编译使用,假设源码文件名称为sdlcairo.c。
gcc -g sdlcairo.c -o sdlcairo `pkg-config --cflags --libs cairo sdl`
在windows xp sp3平台用mingw编译测试通过。
- #include <SDL/SDL.h>
- #include <cairo/cairo.h>
- const int WIDTH = 768, HEIGHT = 576;
- int main(int argc, char** argv)
- {
-
- atexit(SDL_Quit);
- if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
- return -1;
- SDL_Surface *screen = SDL_SetVideoMode( WIDTH, HEIGHT, 0,
- SDL_HWSURFACE | SDL_DOUBLEBUF);
-
- unsigned char data[WIDTH*HEIGHT*4];
- SDL_Surface *sdl_surface = SDL_CreateRGBSurfaceFrom(&data[0],
- WIDTH, HEIGHT, 32, WIDTH*4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
-
- cairo_surface_t *surface = cairo_image_surface_create_for_data(
- &data[0], CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, screen->pitch);
- cairo_t *cr = cairo_create( surface);
- cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY);
- int running = 1;
- while (running) {
- SDL_Event event;
- while( SDL_PollEvent( &event)) {
- if( SDL_QUIT == event.type)
- {
- running = 0;
- }
- else if( SDL_VIDEOEXPOSE == event.type)
- {
- cairo_set_source_rgba(cr, 0, 0, 0, 1);
- cairo_paint(cr);
- cairo_set_source_rgba(cr, 1, 0, 0, 1);
- cairo_arc (cr, WIDTH/2, HEIGHT/2, 76.8, 0, 2 * 3.1416926);
- cairo_fill (cr);
- SDL_BlitSurface( sdl_surface, NULL, screen, NULL);
- }
- }
- SDL_Flip(screen);
- }
- cairo_destroy( cr);
- cairo_surface_destroy( surface);
- SDL_FreeSurface(sdl_surface);
- return 0;
- }
复制代码
我发现程序运行时占用的内核时间相当的多,我的机器是windows xp sp3,intel双核U,集成G31显卡。 |
|