X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=share%2Fitem.c;h=ce272d1d9e7a18f1e31cec0867a03efe88f57d15;hb=4483dfdacd29073b37a6429ca8e123c80deac75a;hp=914127ceb8c6ad505df6eaf218737eed70e9bd74;hpb=2bc33e3f02770aae52883254bbc86091a28fa32c;p=neverball diff --git a/share/item.c b/share/item.c index 914127c..ce272d1 100644 --- a/share/item.c +++ b/share/item.c @@ -15,78 +15,15 @@ #include "item.h" #include "glext.h" #include "vec3.h" -#include "solid.h" +#include "solid_gl.h" #include "image.h" - -#define PI 3.1415926535897932 +#include "config.h" /*---------------------------------------------------------------------------*/ -static void coin_head(int n, float radius, float thick) -{ - int i; - - glBegin(GL_TRIANGLE_FAN); - { - glNormal3f(0.f, 0.f, +1.f); - - for (i = 0; i < n; i++) - { - float x = fcosf(+2.f * PI * i / n); - float y = fsinf(+2.f * PI * i / n); - - glTexCoord2f(+x * 0.5f + 0.5f, +y * 0.5f + 0.5f); - glVertex3f(radius * x, radius * y, +thick); - } - } - glEnd(); -} - -static void coin_tail(int n, float radius, float thick) -{ - int i; - - glBegin(GL_TRIANGLE_FAN); - { - glNormal3f(0.f, 0.f, -1.f); - - for (i = 0; i < n; i++) - { - float x = fcosf(-2.f * PI * i / n); - float y = fsinf(-2.f * PI * i / n); - - glTexCoord2f(-x * 0.5f + 0.5f, +y * 0.5f + 0.5f); - glVertex3f(radius * x, radius * y, -thick); - } - } - glEnd(); -} - -static void coin_edge(int n, float radius, float thick) -{ - int i; - - glBegin(GL_QUAD_STRIP); - { - for (i = 0; i <= n; i++) - { - float x = fcosf(2.f * PI * i / n); - float y = fsinf(2.f * PI * i / n); - - glNormal3f(x, y, 0.0f); - glVertex3f(radius * x, radius * y, +thick); - glVertex3f(radius * x, radius * y, -thick); - } - } - glEnd(); -} - -/*---------------------------------------------------------------------------*/ - -static GLuint item_coin_text; -static GLuint item_grow_text; -static GLuint item_shrink_text; -static GLuint item_list; +static struct s_file item_coin_file; +static struct s_file item_grow_file; +static struct s_file item_shrink_file; void item_color(const struct s_item *hp, float *c) { @@ -116,8 +53,21 @@ void item_color(const struct s_item *hp, float *c) break; case ITEM_GROW: + + c[0] = 0.00f; + c[1] = 0.51f; + c[2] = 0.80f; + + break; + case ITEM_SHRINK: + c[0] = 1.00f; + c[1] = 0.76f; + c[2] = 0.00f; + + break; + default: c[0] = 1.0f; @@ -128,85 +78,41 @@ void item_color(const struct s_item *hp, float *c) } } -void item_init(int b) +void item_init(void) { - int n = b ? 32 : 8; - - item_coin_text = make_image_from_file(IMG_ITEM_COIN); - item_grow_text = make_image_from_file(IMG_ITEM_GROW); - item_shrink_text = make_image_from_file(IMG_ITEM_SHRINK); - - item_list = glGenLists(1); - - glNewList(item_list, GL_COMPILE); - { - glDisable(GL_TEXTURE_2D); - coin_edge(n, COIN_RADIUS, COIN_THICK); - glEnable (GL_TEXTURE_2D); - coin_head(n, COIN_RADIUS, COIN_THICK); - coin_tail(n, COIN_RADIUS, COIN_THICK); - } - glEndList(); + sol_load_gl(&item_coin_file, "item/coin/coin.sol", 0); + sol_load_gl(&item_grow_file, "item/grow/grow.sol", 0); + sol_load_gl(&item_shrink_file, "item/shrink/shrink.sol", 0); } void item_free(void) { - if (glIsList(item_list)) - glDeleteLists(item_list, 1); - - if (glIsTexture(item_coin_text)) - glDeleteTextures(1, &item_coin_text); - - if (glIsTexture(item_grow_text)) - glDeleteTextures(1, &item_grow_text); - - if (glIsTexture(item_shrink_text)) - glDeleteTextures(1, &item_shrink_text); - - item_list = 0; - item_coin_text = 0; - item_grow_text = 0; - item_shrink_text = 0; + sol_free_gl(&item_coin_file); + sol_free_gl(&item_grow_file); + sol_free_gl(&item_shrink_file); } void item_push(int type) { - static const float a[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - static const float s[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - static const float e[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - static const float h[1] = { 10.0f }; - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, a); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, s); - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, e); - glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, h); - glEnable(GL_COLOR_MATERIAL); - - switch (type) - { - case ITEM_COIN: - glBindTexture(GL_TEXTURE_2D, item_coin_text); - break; - - case ITEM_GROW: - glBindTexture(GL_TEXTURE_2D, item_grow_text); - break; - - case ITEM_SHRINK: - glBindTexture(GL_TEXTURE_2D, item_shrink_text); - break; - } } void item_draw(const struct s_item *hp, float r) { float c[3]; + struct s_file *fp = NULL; + + switch (hp->t) + { + case ITEM_COIN: fp = &item_coin_file; break; + case ITEM_GROW: fp = &item_grow_file; break; + case ITEM_SHRINK: fp = &item_shrink_file; break; + } item_color(hp, c); glColor3fv(c); - glCallList(item_list); + sol_draw(fp, 0, 1); } void item_pull(void)