Digital Oscilloscope GUI base on SDL.

Digital Oscilloscope GUI base on SDL.

1.soure code:

 

 

 

2.X86上運行效果圖:

 

 

 

3.How to use SDL APIs:


1).SDL_Init(SDL_INIT_VIDEO) .

Initialize the Video Devices such as Framebuffer ,DireactFB,X11 or OpenGL etc.


2).Set the Video device.

SDL_Surface *screen, *window;

screen = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE);


3).Draw some graphic data on the backbuffer(SWSurface). 

    uint32_t color;
    SDL_Rect rect;
    color = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF);  /* Generate the blue color*/
    rect.x = 0;
    rect.y = 0;
    rect.w = screen->w;
    rect.h = screen->h;
    SDL_FillRect(screen, &rect, color);   /* FillRect function */


4).If you want to show some on the screen,please call

SDL_UpdateRect(screen, 30, 30, 480, 320);


5).Create a new RGB surface. 

*window = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
            0xFF << 24, 0xff << 16, 0xFF << 8, 0xFF);


6).BitBlt function(Copy source surface to destination surface).

    if ( SDL_BlitSurface(src, NULL, dst, &update) < 0 ) {
        fprintf(stderr, "Blit failed: %s/n", SDL_GetError());
    }


7).How to get input events.

    while (!quit) { 
        render(window, screen);
        SDL_UpdateRect(screen, 30, 30, 480, 320);    
        SDL_Event    event;
        uint32_t ret = 0;    
        //j = 0;    
        while (ret = SDL_PollEvent(&event)) { 

            /* when get input events,this function return 1,or 0,

                and it's not blocked function */ 
            //printf("j = %d,ret = %d/n", j++, ret);
            switch(event.type) {
                /*case SDL_MOUSEBUTTONDOWN:
                    break;*/
                case SDL_KEYDOWN:
                    if (event.key.keysym.sym == SDLK_ESCAPE) {
                        quit = SDL_TRUE;
                    }
                    break;
                case SDL_QUIT:
                    quit = SDL_TRUE;
                    break;
            }
        }    
        SDL_Delay(50);
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章