comparison ext/guichan-0.8.2/examples/openglallegro.hpp @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 /*
2 * Code that sets up an OpenGL application with Guichan using the
3 * Guichan OpenGL back end and the Allegro back end (as OpenGL cannot
4 * load images nor check for user input an additional back end needs
5 * to be used).
6 */
7
8 // The openglallegroimageloader.hpp header file needs to be included
9 // in order to get the image loader that uses OpenGL and Allegro.
10 #include <guichan/opengl/openglallegroimageloader.hpp>
11 #include <guichan.hpp>
12 #include <guichan/opengl.hpp>
13 #include <guichan/allegro.hpp>
14
15 namespace openglallegro
16 {
17 // All back ends contain objects to make Guichan work on a
18 // specific target. They are a Graphics object to make Guichan
19 // able to draw itself using OpenGL, an input objec to make
20 // Guichan able to get user input using Allegro and an ImageLoader
21 // object to make Guichan able to load images using OpenGL and Allegro.
22 gcn::OpenGLGraphics* graphics;
23 gcn::AllegroInput* input;
24 gcn::OpenGLAllegroImageLoader* imageLoader;
25
26 /**
27 * Initialises the OpenGL and Allegro application. This function creates the global
28 * Gui object that can be populated by various examples.
29 */
30 void init()
31 {
32 // We simply initialise OpenGL and Allegro as we would do with any OpenGL
33 // and Allegro application.
34 allegro_init();
35
36 install_allegro_gl();
37
38 allegro_gl_clear_settings();
39 allegro_gl_set (AGL_COLOR_DEPTH, 32);
40 allegro_gl_set (AGL_Z_DEPTH, 24);
41 allegro_gl_set (AGL_FULLSCREEN, TRUE);
42 allegro_gl_set (AGL_DOUBLEBUFFER, 1);
43 allegro_gl_set (AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_Z_DEPTH | AGL_DOUBLEBUFFER);
44
45 set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0);
46
47 install_keyboard();
48 install_mouse();
49 install_timer();
50
51 glViewport(0, 0, 640, 480);
52 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
53
54 // Now it's time to initialise the Guichan OpenGL back end
55 // and the Guichan Allegro back end.
56
57 imageLoader = new gcn::OpenGLAllegroImageLoader();
58 // The ImageLoader Guichan should use needs to be passed to the Image object
59 // using a static function.
60 gcn::Image::setImageLoader(imageLoader);
61 graphics = new gcn::OpenGLGraphics();
62 // We need to tell the OpenGL Graphics object how big the screen is.
63 graphics->setTargetPlane(640, 480);
64 input = new gcn::AllegroInput();
65
66 // Now we create the Gui object to be used with this OpenGL
67 // and Allegro application.
68 globals::gui = new gcn::Gui();
69 // The Gui object needs a Graphics to be able to draw itself and an Input
70 // object to be able to check for user input. In this case we provide the
71 // Gui object with OpenGL and Allegro implementations of these objects hence
72 // making Guichan able to utilise OpenGL and Allegro.
73 globals::gui->setGraphics(graphics);
74 globals::gui->setInput(input);
75 }
76
77 /**
78 * Halts the OpenGL and Allegro application.
79 */
80 void halt()
81 {
82 delete globals::gui;
83
84 delete imageLoader;
85 delete input;
86 delete graphics;
87 }
88
89 /**
90 * Runs the OpenGL and Allegro application.
91 */
92 void run()
93 {
94 while(!key[KEY_ESC])
95 {
96 // Now we let the Gui object perform its logic.
97 globals::gui->logic();
98 // Now we let the Gui object draw itself.
99 globals::gui->draw();
100
101 // Now we draw the mouse cursor.
102 allegro_gl_set_allegro_mode();
103 show_mouse(screen);
104 algl_draw_mouse();
105 allegro_gl_unset_allegro_mode();
106
107 // Finally we update the screen.
108 allegro_gl_flip();
109 }
110 }
111 }