Video Initialization
From Agar
After invoking AG_InitCore(), an Agar application must also initialize the graphics facilities.
Contents |
Using the default mode
Starting from Agar-1.4, a typical Agar application will initialize the graphics facilities by calling the 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 <agar/core.h> #include <agar/gui.h> 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 AG_InitGraphics(), the 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 <agar/core.h> #include <agar/gui.h> 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, AG_ResizeDisplay() can be used to request resizing of the application window to a specified size.
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("<OpenGL>");
Then 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("<SDL>");
Then AG_InitGraphics() will immediately fail if an SDL display cannot be obtained.
The AG_InitVideoSDL() function allows Agar to attach to an existing SDL display surface:
/* * Sample Agar application using an existing SDL surface. */ #include <agar/core.h> #include <agar/gui.h> 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); }

