After invoking {{Fn|AG_InitCore}}, an Agar application must also initialize the graphics facilities. == Using the default mode == Starting from [[Agar-1.4]], a typical Agar application will initialize the graphics facilities by calling the {{Fn|AG_InitGraphics}} function. Unless a specific driver is requested, Agar will pick the "best" available driver for the current platform: /* * Example Agar application using AG_InitGraphics(). * Error checking omitted. */ #include #include int main(int argc, char *argv[]) { AG_InitCore("myapp", 0); AG_InitGraphics(NULL); AG_TextMsg(AG_MSG_INFO, "Hello, world!"); AG_EventLoop(); return (0); } == Single-window vs. multiple-window drivers == Furthermore, Agar drivers may be of the '''single-window''', or '''multiple-window''' variety. When single-window drivers such as [[sdlfb]] and [[sdlgl]] are used, a global "video context" is defined, and Agar becomes the window manager. Multiple-window drivers such as [[glx]] and [[wgl]] allow Agar to interface with some existing window system. As an alternative to {{Fn|AG_InitGraphics}}, the {{Fn|AG_InitVideo}} function can also be used. However, it will only select among the "single-window" drivers, and create a video context of specified geometry: /* * Example Agar application using AG_InitVideo(). * Omitted error checking. */ #include #include int main(int argc, char *argv[]) { AG_InitCore("myapp", 0); AG_InitVideo(320,240,32, AG_VIDEO_RESIZABLE); AG_TextMsg(AG_MSG_INFO, "Hello, world!"); AG_EventLoop(); return (0); } == Resizing the display == On platforms where there is an underlying window manager, {{Fn|AG_ResizeDisplay}} can be used to request resizing of the application window to a specified size. {{Fn|AG_SetVideoResizeCallback}} can be used to register a callback routine to be invoked whenever the application window has been resized. == OpenGL Mode == By default, Agar selects the display mode most suitable for the current platform. On modern platforms, [[OpenGL]] is usually selected by default, but it is not necessarily the case. If your application is OpenGL-specific, you can force OpenGL using: AG_InitGraphics(""); Then {{Fn|AG_InitGraphics}} will immediately fail if an OpenGL rendering context cannot be obtained. == Forcing SDL Mode == If support for [[SDL]] was compiled into Agar, it can also be forced to use a SDL-based river using: AG_InitGraphics(""); Then {{Fn|AG_InitGraphics}} will immediately fail if an SDL display cannot be obtained. The {{Fn|AG_InitVideoSDL}} function allows Agar to attach to an existing SDL display surface: /* * Sample Agar application using an existing SDL surface. */ #include #include int main(int argc, char *argv[]) { SDL_Surface *screen; SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(640,480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); AG_InitCore("myapp", 0); AG_InitVideoSDL(screen, 0); AG_TextMsg(AG_MSG_INFO, "Hello, SDL!"); AG_EventLoop(); return (0); } == See also == * [[Custom event loop]] * [[Integrating Agar in an existing GL application]] * {{man3|AG_View}}, {{man3|AG_Widget}}, {{man3|AG_Window}}, {{man3|AG_Surface}}, {{man3|AG_Text}} [[Category:Tutorials]] [[Category:Agar-GUI]] [[Category:Graphics]]