1 // $Id$
2
3 // Fish Supper
4 // Copyright 2006, 2007, 2009, 2010 Matthew Clarke <mafferyew@googlemail.com>
5 //
6 // This file is part of Fish Supper.
7 //
8 // Fish Supper is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // Fish Supper is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Fish Supper. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23
24 #include "FS_gfx.h"
25
26
27
28
FS_gfx()29 FS::FS_gfx::FS_gfx()
30 {
31 init();
32
33 } // FS::FS_gfx::FS_gfx
34
~FS_gfx()35 FS::FS_gfx::~FS_gfx()
36 {
37 // clean up
38 for ( int i = 0; i < NUM_SPRITES; ++i )
39 {
40 glDeleteTextures( 1, &(my_textures[i].tex_handle) );
41 } // for
42
43 for ( int i = 0; i < NUM_BACKGROUNDS; ++i )
44 {
45 delete my_backgrounds[i];
46 } // for
47
48 for ( int i = 0; i < NUM_FONTS; ++i )
49 {
50 delete my_fonts[i];
51 } // for
52
53 } // FS::FS_gfx::~FS_gfx
54
55
56
57
init()58 void FS::FS_gfx::init()
59 {
60 std::string path;
61 char digits[4];
62
63 // sprites
64 // store texture dimensions here
65 int w;
66 int h;
67
68 for ( int i = 0; i < NUM_SPRITES; ++i )
69 {
70 path = (PKG_DATA_DIR "/images/fs_sprite_");
71 sprintf(digits, "%03d", i);
72 path += digits;
73 path += ".png";
74
75 GLuint th = Mafferyew::Useful_gl::create_opengl_texture_rgba(path, &w, &h);
76 Texture tex = { th, w, h };
77 my_textures.push_back(tex);
78 } // for
79
80 // backgrounds
81 for ( int i = 0; i < NUM_BACKGROUNDS; ++i )
82 {
83 path = (PKG_DATA_DIR "/images/fs_bg_");
84 sprintf(digits, "%03d", i);
85 path += digits;
86 path += ".png";
87
88 Mafferyew::Background_image* bg_img = new Mafferyew::Background_image(path);
89 my_backgrounds.push_back(bg_img);
90 } // for
91
92 // fonts
93 for ( int i = 0; i < NUM_FONTS; ++i )
94 {
95 path = (PKG_DATA_DIR "/images/fs_font_");
96 sprintf(digits, "%03d", i);
97 path += digits;
98 path += ".png";
99
100 Mafferyew::SFont_gl* font = new Mafferyew::SFont_gl(path);
101 my_fonts.push_back(font);
102 } // for
103
104 } // FS::FS_gfx::init
105
clear_screen()106 void FS::FS_gfx::clear_screen()
107 {
108 glClearColor( 0.42, 0.81, 0.93, 0.0 );
109 glClear(GL_COLOR_BUFFER_BIT);
110
111 } // FS::FS_gfx::clear_screen
112