Hack share/item to use OBJ geometry
[neverball] / share / item.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "item.h"
16 #include "glext.h"
17 #include "vec3.h"
18 #include "solid_gl.h"
19 #include "image.h"
20 #include "config.h"
21
22 /*---------------------------------------------------------------------------*/
23
24 static struct s_file item_coin_file;
25 static struct s_file item_grow_file;
26 static struct s_file item_shrink_file;
27
28 void item_color(const struct s_item *hp, float *c)
29 {
30     switch (hp->t)
31     {
32
33     case ITEM_COIN:
34
35         if (hp->n >= 1)
36         {
37             c[0] = 1.0f;
38             c[1] = 1.0f;
39             c[2] = 0.2f;
40         }
41         if (hp->n >= 5)
42         {
43             c[0] = 1.0f;
44             c[1] = 0.2f;
45             c[2] = 0.2f;
46         }
47         if (hp->n >= 10)
48         {
49             c[0] = 0.2f;
50             c[1] = 0.2f;
51             c[2] = 1.0f;
52         }
53         break;
54
55     case ITEM_GROW:
56     case ITEM_SHRINK:
57
58     default:
59
60         c[0] = 1.0f;
61         c[1] = 1.0f;
62         c[2] = 1.0f;
63
64         break;
65     }
66 }
67
68 void item_init(void)
69 {
70     int T = config_get_d(CONFIG_TEXTURES);
71
72     sol_load_gl(&item_coin_file, config_data("item/coin/coin.sol"), T, 0);
73     sol_load_gl(&item_grow_file, config_data("item/grow/grow.sol"), T, 0);
74     sol_load_gl(&item_shrink_file, config_data("item/shrink/shrink.sol"), T, 0);
75 }
76
77 void item_free(void)
78 {
79     sol_free_gl(&item_coin_file);
80     sol_free_gl(&item_grow_file);
81     sol_free_gl(&item_shrink_file);
82 }
83
84 void item_push(int type)
85 {
86     glEnable(GL_COLOR_MATERIAL);
87 }
88
89 void item_draw(const struct s_item *hp, float r)
90 {
91     float c[3];
92     struct s_file *fp = NULL;
93
94     switch (hp->t)
95     {
96     case ITEM_COIN:   fp = &item_coin_file;   break;
97     case ITEM_GROW:   fp = &item_grow_file;   break;
98     case ITEM_SHRINK: fp = &item_shrink_file; break;
99     }
100
101     item_color(hp, c);
102
103     glColor3fv(c);
104     sol_draw(fp, 0, 1);
105 }
106
107 void item_pull(void)
108 {
109     glColor3f(1.0f, 1.0f, 1.0f);
110     glDisable(GL_COLOR_MATERIAL);
111 }
112
113 /*---------------------------------------------------------------------------*/
114