Ported the mtrl loft to putt.
[neverball] / putt / game.c
index 80652ee..fd0157a 100644 (file)
@@ -152,7 +152,8 @@ static void game_draw_vect_prim(const struct s_vary *fp, GLenum mode)
     glEnd();
 }
 
-static void game_draw_vect(const struct s_vary *fp)
+static const struct d_mtrl *game_draw_vect(const struct d_mtrl *mq,
+                                           const struct s_vary *fp)
 {
     if (view_m > 0.f)
     {
@@ -177,10 +178,12 @@ static void game_draw_vect(const struct s_vary *fp)
         glPopAttrib();
         glPopAttrib();
     }
+    return mq;
 }
 
-static void game_draw_balls(const struct s_vary *fp,
-                            const float *bill_M, float t)
+static const struct d_mtrl *game_draw_balls(const struct d_mtrl *mq,
+                                            const struct s_vary *fp,
+                                            const float *bill_M, float t)
 {
     static const GLfloat color[5][4] = {
         { 1.0f, 1.0f, 1.0f, 0.7f },
@@ -214,7 +217,7 @@ static void game_draw_balls(const struct s_vary *fp,
                          fp->uv[ui].r);
 
                 glColor4fv(color[ui]);
-                ball_draw(ball_M, pend_M, bill_M, t);
+                mq = ball_draw(mq, ball_M, pend_M, bill_M, t);
             }
             glPopMatrix();
         }
@@ -233,7 +236,7 @@ static void game_draw_balls(const struct s_vary *fp,
                           color[ui][1],
                           color[ui][2], 0.5f);
 
-                mark_draw();
+                mq = mark_draw(mq);
             }
             glPopMatrix();
         }
@@ -241,9 +244,12 @@ static void game_draw_balls(const struct s_vary *fp,
 
     glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
     glDisable(GL_COLOR_MATERIAL);
+
+    return mq;
 }
 
-static void game_draw_goals(const struct s_base *fp)
+static const struct d_mtrl *game_draw_goals(const struct d_mtrl *mq,
+                                            const struct s_base *fp)
 {
     int zi;
 
@@ -254,13 +260,15 @@ static void game_draw_goals(const struct s_base *fp)
             glTranslatef(fp->zv[zi].p[0],
                          fp->zv[zi].p[1],
                          fp->zv[zi].p[2]);
-            flag_draw();
+            mq = flag_draw(mq);
         }
         glPopMatrix();
     }
+    return mq;
 }
 
-static void game_draw_jumps(const struct s_base *fp)
+static const struct d_mtrl *game_draw_jumps(const struct d_mtrl *mq,
+                                            const struct s_base *fp)
 {
     float t = 0.001f * SDL_GetTicks();
     int ji;
@@ -274,13 +282,15 @@ static void game_draw_jumps(const struct s_base *fp)
                          fp->jv[ji].p[2]);
 
             glScalef(fp->jv[ji].r, 1.f, fp->jv[ji].r);
-            jump_draw(t, !jump_e);
+            mq = jump_draw(mq, t, !jump_e);
         }
         glPopMatrix();
     }
+    return mq;
 }
 
-static void game_draw_swchs(const struct s_vary *fp)
+static const struct d_mtrl *game_draw_swchs(const struct d_mtrl *mq,
+                                            const struct s_vary *fp)
 {
     int xi;
 
@@ -298,10 +308,11 @@ static void game_draw_swchs(const struct s_vary *fp)
                          xp->base->p[2]);
 
             glScalef(xp->base->r, 1.f, xp->base->r);
-            swch_draw(xp->f, xp->e);
+            mq = swch_draw(mq, xp->f, xp->e);
         }
         glPopMatrix();
     }
+    return mq;
 }
 
 /*---------------------------------------------------------------------------*/
@@ -316,6 +327,7 @@ void game_draw(int pose, float t)
     const float light_p[4] = { 8.f, 32.f, 8.f, 0.f };
 
     const struct s_draw *fp = &file.draw;
+    const struct d_mtrl *mq = sol_draw_enable();
 
     float fov = FOV;
 
@@ -344,7 +356,7 @@ void game_draw(int pose, float t)
         glPushMatrix();
         {
             glTranslatef(view_p[0], view_p[1], view_p[2]);
-            back_draw(0);
+            mq = back_draw(mq, 0);
         }
         glPopMatrix();
 
@@ -353,14 +365,7 @@ void game_draw(int pose, float t)
 
         /* Draw the floor. */
 
-        sol_draw(fp, 0, 1);
-
-        if (config_get_d(CONFIG_SHADOW) && !pose)
-        {
-            shad_draw_set();
-            sol_shad(fp, ball);
-            shad_draw_clr();
-        }
+        mq = sol_draw(fp, mq, 0, 1);
 
         /* Draw the game elements. */
 
@@ -369,8 +374,8 @@ void game_draw(int pose, float t)
 
         if (pose == 0)
         {
-            game_draw_balls(fp->vary, T, t);
-            game_draw_vect(fp->vary);
+            mq = game_draw_balls(mq, fp->vary, T, t);
+            mq = game_draw_vect(mq, fp->vary);
         }
 
         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   a);
@@ -382,9 +387,9 @@ void game_draw(int pose, float t)
         glDisable(GL_LIGHTING);
         glDepthMask(GL_FALSE);
         {
-            game_draw_goals(fp->base);
-            game_draw_jumps(fp->base);
-            game_draw_swchs(fp->vary);
+            mq = game_draw_goals(mq, fp->base);
+            mq = game_draw_jumps(mq, fp->base);
+            mq = game_draw_swchs(mq, fp->vary);
         }
         glDepthMask(GL_TRUE);
         glEnable(GL_LIGHTING);
@@ -393,6 +398,8 @@ void game_draw(int pose, float t)
     glPopMatrix();
     glPopAttrib();
     video_pop_matrix();
+
+    sol_draw_disable(mq);
 }
 
 /*---------------------------------------------------------------------------*/