SDL's Chinese information is relatively small, recommend an English website inside the very detailed click Open link to solve my many doubts.
Recently in porting Ucgui to Android, Ucgui's Windows demo can be used to draw in one thread and refresh in another thread. Using Ucgui in Android is also possible with SDL as a canvas, painting in sub-threads, and refreshing in the main thread. The code is as follows:
/*this source code copyrighted by Lazy Foo ' Productions (2004-2013) and is not being redistributed without written Permissio N.*///using SDL and Standard io#include <SDL.h> #include <stdio.h> #include <stdbool.h> #include "GUI.h "//screen dimension constantsextern int Screen_width;extern int screen_height;//starts up SDL and creates window//loads me Diabool Loadmedia ();//Load Picture//frees media and shuts down sdlvoid close ();//the window we'll be rendering Toextern Sdl_window * G_screen_window;//the surface contained by the Windowextern sdl_surface* g_screen_surface;//the image We'll load and s How on the screensdl_surface* gxout = Null;bool Loadmedia () {//loading success Flagbool success = True;//load Splash image Gxout = Sdl_loadbmp ("X.bmp"), if (gxout = = NULL) {sdl_logerror (sdl_log_category_application, "Unable to load image%s! SDL Error:%s\n "," 03_event_driven_programming/x.bmp ", Sdl_geterror ()); success = false;} return success;} void Close () {//deallocate surfacesdl_freesurface (GXout); gxout = Null;//destroy Windowsdl_destroywindow (g_screen_window); G_screen_window = Null;//quit SDL subsystemsSDL_ Quit ();} void Thread1 (void *pdata) {maintask (0);//The Paint function in the sub-thread is here Sdl_log ("Thread runing");} int sdl_main (int argc, char* args[]) {//start up SDL and create windowgui_init ();//Initialize Windows and Surface//load mediaif (!lo Admedia ()) {printf ("Failed to load media!\n");} else {//main loop flagbool quit = False;//event handlersdl_event e; Sdl_thread *thread = Sdl_createthread (Thread1, "Testthread", (void *) NULL);//while application is Runningwhile (!quit) {/ /handle events on Queuewhile (Sdl_pollevent (&e)! = 0) {//user requests quitif (E.type = = sdl_quit) {QUIT = true;} if (E.type = = Sdl_fingerup) {quit = true;}} Apply the Image//update the Surfacesdl_updatewindowsurface (G_screen_window); Sdl_log ("Invalidate");}} Free resources and close sdlclose (); return 0;}
Using multi-threaded drawing in SDL2