Compute body velocity by snapshotting body position at t and t + dt
[neverball] / share / solid_gl.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 <SDL.h>
16 #include <SDL_rwops.h>
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <math.h>
22
23 #include "glext.h"
24 #include "vec3.h"
25 #include "image.h"
26 #include "base_image.h"
27 #include "solid_gl.h"
28 #include "solid_phys.h"
29 #include "base_config.h"
30 #include "lang.h"
31
32 /*---------------------------------------------------------------------------*/
33
34 static int sol_enum_mtrl(const struct s_file *fp,
35                          const struct s_body *bp, int mi)
36 {
37     int li, gi, c = 0;
38
39     /* Count all lump geoms with this material. */
40
41     for (li = 0; li < bp->lc; li++)
42     {
43         int g0 = fp->lv[bp->l0 + li].g0;
44         int gc = fp->lv[bp->l0 + li].gc;
45
46         for (gi = 0; gi < gc; gi++)
47             if (fp->gv[fp->iv[g0 + gi]].mi == mi)
48                 c++;
49     }
50
51     /* Count all body geoms with this material. */
52
53     for (gi = 0; gi < bp->gc; gi++)
54         if (fp->gv[fp->iv[bp->g0 + gi]].mi == mi)
55             c++;
56
57     return c;
58 }
59
60 static int sol_enum_body(const struct s_file *fp,
61                          const struct s_body *bp, int fl)
62 {
63     int mi, c = 0;
64
65     /* Count all geoms with this flag. */
66
67     for (mi = 0; mi < fp->mc; mi++)
68         if (fp->mv[mi].fl & fl)
69             c = c + sol_enum_mtrl(fp, bp, mi);
70
71     return c;
72 }
73
74 /*---------------------------------------------------------------------------*/
75
76 int sol_reflective(const struct s_file *fp)
77 {
78     int bi;
79
80     for (bi = 0; bi < fp->bc; bi++)
81         if (fp->bv[bi].rl)
82             return 1;
83
84     return 0;
85 }
86
87 /*---------------------------------------------------------------------------*/
88
89 #define tobyte(f) ((GLubyte) (f * 255.0f))
90
91 #define color_cmp(a, b) (tobyte((a)[0]) == tobyte((b)[0]) && \
92                          tobyte((a)[1]) == tobyte((b)[1]) && \
93                          tobyte((a)[2]) == tobyte((b)[2]) && \
94                          tobyte((a)[3]) == tobyte((b)[3]))
95
96 static struct s_mtrl default_mtrl =
97 {
98     { 0.8f, 0.8f, 0.8f, 1.0f },
99     { 0.2f, 0.2f, 0.2f, 1.0f },
100     { 0.0f, 0.0f, 0.0f, 1.0f },
101     { 0.0f, 0.0f, 0.0f, 1.0f },
102     { 0.0f, }, 0.0f, M_OPAQUE, 0, ""
103 };
104
105 static const struct s_mtrl *sol_draw_mtrl(const struct s_file *fp,
106                                           const struct s_mtrl *mp,
107                                           const struct s_mtrl *mq)
108 {
109     /* Change material properties only as needed. */
110
111     if (!color_cmp(mp->a, mq->a))
112         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   mp->a);
113     if (!color_cmp(mp->d, mq->d))
114         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,   mp->d);
115     if (!color_cmp(mp->s, mq->s))
116         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  mp->s);
117     if (!color_cmp(mp->e, mq->e))
118         glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,  mp->e);
119     if (tobyte(mp->h[0]) != tobyte(mq->h[0]))
120         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mp->h);
121
122     /* Bind the texture. */
123
124     if (mp->o != mq->o)
125         glBindTexture(GL_TEXTURE_2D, mp->o);
126
127     /* Enable environment mapping. */
128
129     if ((mp->fl & M_ENVIRONMENT) && !(mq->fl & M_ENVIRONMENT))
130     {
131         glEnable(GL_TEXTURE_GEN_S);
132         glEnable(GL_TEXTURE_GEN_T);
133
134         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
135         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
136     }
137
138     /* Disable environment mapping. */
139
140     if ((mq->fl & M_ENVIRONMENT) && !(mp->fl & M_ENVIRONMENT))
141     {
142         glDisable(GL_TEXTURE_GEN_S);
143         glDisable(GL_TEXTURE_GEN_T);
144     }
145
146     /* Enable additive blending. */
147
148     if ((mp->fl & M_ADDITIVE) && !(mq->fl & M_ADDITIVE))
149         glBlendFunc(GL_ONE, GL_ONE);
150
151     /* Enable standard blending. */
152
153     if ((mq->fl & M_ADDITIVE) && !(mp->fl & M_ADDITIVE))
154         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
155
156     /* Enable visibility-from-behind. */
157
158     if ((mp->fl & M_TWO_SIDED) && !(mq->fl & M_TWO_SIDED))
159     {
160         glDisable(GL_CULL_FACE);
161         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
162     }
163
164     /* Disable visibility-from-behind. */
165
166     if ((mq->fl & M_TWO_SIDED) && !(mp->fl & M_TWO_SIDED))
167     {
168         glEnable(GL_CULL_FACE);
169         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
170     }
171
172     /* Enable decal offset. */
173
174     if ((mp->fl & M_DECAL) && !(mq->fl & M_DECAL))
175     {
176         glEnable(GL_POLYGON_OFFSET_FILL);
177         glPolygonOffset(-1.0f, -2.0f);
178     }
179
180     /* Disable decal offset. */
181
182     if ((mq->fl & M_DECAL) && !(mp->fl & M_DECAL))
183         glDisable(GL_POLYGON_OFFSET_FILL);
184
185     return mp;
186 }
187
188 static const struct s_mtrl *sol_back_bill(const struct s_file *fp,
189                                           const struct s_bill *rp,
190                                           const struct s_mtrl *mp, float t)
191 {
192     float T = (rp->t > 0.0f) ? (fmodf(t, rp->t) - rp->t / 2) : 0.0f;
193
194     float w = rp->w[0] + rp->w[1] * T + rp->w[2] * T * T;
195     float h = rp->h[0] + rp->h[1] * T + rp->h[2] * T * T;
196
197     if (w > 0 && h > 0)
198     {
199         float rx = rp->rx[0] + rp->rx[1] * T + rp->rx[2] * T * T;
200         float ry = rp->ry[0] + rp->ry[1] * T + rp->ry[2] * T * T;
201         float rz = rp->rz[0] + rp->rz[1] * T + rp->rz[2] * T * T;
202
203         glPushMatrix();
204         {
205             float y0 = (rp->fl & B_EDGE) ? 0 : -h / 2;
206             float y1 = (rp->fl & B_EDGE) ? h : +h / 2;
207
208             glRotatef(ry, 0.0f, 1.0f, 0.0f);
209             glRotatef(rx, 1.0f, 0.0f, 0.0f);
210             glTranslatef(0.0f, 0.0f, -rp->d);
211
212             if (rp->fl & B_FLAT)
213             {
214                 glRotatef(-rx - 90.0f, 1.0f, 0.0f, 0.0f);
215                 glRotatef(-ry,         0.0f, 0.0f, 1.0f);
216             }
217             if (rp->fl & B_EDGE)
218                 glRotatef(-rx,         1.0f, 0.0f, 0.0f);
219
220             glRotatef(rz, 0.0f, 0.0f, 1.0f);
221
222             mp = sol_draw_mtrl(fp, fp->mv + rp->mi, mp);
223
224             glBegin(GL_QUADS);
225             {
226                 glTexCoord2f(0.0f, 0.0f); glVertex2f(-w / 2, y0);
227                 glTexCoord2f(1.0f, 0.0f); glVertex2f(+w / 2, y0);
228                 glTexCoord2f(1.0f, 1.0f); glVertex2f(+w / 2, y1);
229                 glTexCoord2f(0.0f, 1.0f); glVertex2f(-w / 2, y1);
230             }
231             glEnd();
232         }
233         glPopMatrix();
234     }
235
236     return mp;
237 }
238
239 /*---------------------------------------------------------------------------*/
240
241 void sol_back(const struct s_file *fp, float n, float f, float t)
242 {
243     const struct s_mtrl *mp = &default_mtrl;
244
245     int ri;
246
247     /* Render all billboards in the given range. */
248
249     glDisable(GL_LIGHTING);
250     glDepthMask(GL_FALSE);
251     {
252         for (ri = 0; ri < fp->rc; ri++)
253             if (n <= fp->rv[ri].d && fp->rv[ri].d < f)
254                 mp = sol_back_bill(fp, fp->rv + ri, mp, t);
255
256         mp = sol_draw_mtrl(fp, &default_mtrl, mp);
257     }
258     glDepthMask(GL_TRUE);
259     glEnable(GL_LIGHTING);
260 }
261
262 /*---------------------------------------------------------------------------*/
263 /*
264  * The  following code  renders a  body in  a  ludicrously inefficient
265  * manner.  It iterates the materials and scans the data structure for
266  * geometry using each.  This  has the effect of absolutely minimizing
267  * material  changes,  texture  bindings,  and  Begin/End  pairs,  but
268  * maximizing trips through the data.
269  *
270  * However, this  is only done once  for each level.   The results are
271  * stored in display lists.  Thus, it is well worth it.
272  */
273
274 static void sol_draw_geom(const struct s_file *fp,
275                           const struct s_geom *gp, int mi)
276 {
277     if (gp->mi == mi)
278     {
279         const float *ui = fp->tv[gp->ti].u;
280         const float *uj = fp->tv[gp->tj].u;
281         const float *uk = fp->tv[gp->tk].u;
282
283         const float *ni = fp->sv[gp->si].n;
284         const float *nj = fp->sv[gp->sj].n;
285         const float *nk = fp->sv[gp->sk].n;
286
287         const float *vi = fp->vv[gp->vi].p;
288         const float *vj = fp->vv[gp->vj].p;
289         const float *vk = fp->vv[gp->vk].p;
290
291         glTexCoord2fv(ui);
292         glNormal3fv(ni);
293         glVertex3fv(vi);
294
295         glTexCoord2fv(uj);
296         glNormal3fv(nj);
297         glVertex3fv(vj);
298
299         glTexCoord2fv(uk);
300         glNormal3fv(nk);
301         glVertex3fv(vk);
302     }
303 }
304
305 static void sol_draw_lump(const struct s_file *fp,
306                           const struct s_lump *lp, int mi)
307 {
308     int i;
309
310     for (i = 0; i < lp->gc; i++)
311         sol_draw_geom(fp, fp->gv + fp->iv[lp->g0 + i], mi);
312 }
313
314 static const struct s_mtrl *sol_draw_body(const struct s_file *fp,
315                                           const struct s_body *bp,
316                                           const struct s_mtrl *mp,
317                                           int fl, int decal)
318 {
319     int mi, li, gi;
320
321     /* Iterate all materials of the correct opacity. */
322
323     for (mi = 0; mi < fp->mc; mi++)
324         if ((fp->mv[mi].fl & fl) && (fp->mv[mi].fl & M_DECAL) == decal)
325         {
326             if (sol_enum_mtrl(fp, bp, mi))
327             {
328                 /* Set the material state. */
329
330                 mp = sol_draw_mtrl(fp, fp->mv + mi, mp);
331
332                 /* Render all geometry of that material. */
333
334                 glBegin(GL_TRIANGLES);
335                 {
336                     for (li = 0; li < bp->lc; li++)
337                         sol_draw_lump(fp, fp->lv + bp->l0 + li, mi);
338                     for (gi = 0; gi < bp->gc; gi++)
339                         sol_draw_geom(fp, fp->gv + fp->iv[bp->g0 + gi], mi);
340                 }
341                 glEnd();
342             }
343         }
344
345     return mp;
346 }
347
348 static void sol_draw_list(const struct s_file *fp,
349                           const struct s_body *bp, GLuint list)
350 {
351     float p[3];
352
353     sol_body_p(p, fp, bp->pi, bp->t);
354
355     glPushMatrix();
356     {
357         /* Translate a moving body. */
358
359         glTranslatef(p[0], p[1], p[2]);
360
361         /* Draw the body. */
362
363         glCallList(list);
364     }
365     glPopMatrix();
366 }
367
368 void sol_draw(const struct s_file *fp, int depthmask, int depthtest)
369 {
370     int bi;
371
372     /* Render all opaque geometry into the color and depth buffers. */
373
374     for (bi = 0; bi < fp->bc; bi++)
375         if (fp->bv[bi].ol)
376             sol_draw_list(fp, fp->bv + bi, fp->bv[bi].ol);
377
378     /* Render all translucent geometry into only the color buffer. */
379
380     if (depthtest == 0) glDisable(GL_DEPTH_TEST);
381     if (depthmask == 0) glDepthMask(GL_FALSE);
382     {
383         for (bi = 0; bi < fp->bc; bi++)
384             if (fp->bv[bi].tl)
385                 sol_draw_list(fp, fp->bv + bi, fp->bv[bi].tl);
386     }
387     if (depthmask == 0) glDepthMask(GL_TRUE);
388     if (depthtest == 0) glEnable(GL_DEPTH_TEST);
389 }
390
391 void sol_bill(const struct s_file *fp, const float *M, float t)
392 {
393     const struct s_mtrl *mp = &default_mtrl;
394
395     int ri;
396
397     for (ri = 0; ri < fp->rc; ++ri)
398     {
399         const struct s_bill *rp = fp->rv + ri;
400
401         float T = rp->t * t;
402         float S = fsinf(T);
403
404         float w  = rp->w [0] + rp->w [1] * T + rp->w [2] * S;
405         float h  = rp->h [0] + rp->h [1] * T + rp->h [2] * S;
406         float rx = rp->rx[0] + rp->rx[1] * T + rp->rx[2] * S;
407         float ry = rp->ry[0] + rp->ry[1] * T + rp->ry[2] * S;
408         float rz = rp->rz[0] + rp->rz[1] * T + rp->rz[2] * S;
409
410         mp = sol_draw_mtrl(fp, fp->mv + rp->mi, mp);
411
412         glPushMatrix();
413         {
414             glTranslatef(rp->p[0], rp->p[1], rp->p[2]);
415
416             if (M && ((rp->fl & B_NOFACE) == 0)) glMultMatrixf(M);
417
418             if (fabsf(rx) > 0.0f) glRotatef(rx, 1.0f, 0.0f, 0.0f);
419             if (fabsf(ry) > 0.0f) glRotatef(ry, 0.0f, 1.0f, 0.0f);
420             if (fabsf(rz) > 0.0f) glRotatef(rz, 0.0f, 0.0f, 1.0f);
421
422             glBegin(GL_QUADS);
423             {
424                 glTexCoord2f(0.0f, 0.0f); glVertex2f(-w / 2, -h / 2);
425                 glTexCoord2f(1.0f, 0.0f); glVertex2f(+w / 2, -h / 2);
426                 glTexCoord2f(1.0f, 1.0f); glVertex2f(+w / 2, +h / 2);
427                 glTexCoord2f(0.0f, 1.0f); glVertex2f(-w / 2, +h / 2);
428             }
429             glEnd();
430         }
431         glPopMatrix();
432     }
433
434     mp = sol_draw_mtrl(fp, &default_mtrl, mp);
435 }
436
437 void sol_refl(const struct s_file *fp)
438 {
439     int bi;
440
441     /* Render all reflective geometry into the color and depth buffers. */
442
443     for (bi = 0; bi < fp->bc; bi++)
444         if (fp->bv[bi].rl)
445             sol_draw_list(fp, fp->bv + bi, fp->bv[bi].rl);
446 }
447
448 /*---------------------------------------------------------------------------*/
449
450 static void sol_shad_geom(const struct s_file *fp,
451                           const struct s_geom *gp, int mi)
452 {
453     if (gp->mi == mi)
454     {
455         const float *vi = fp->vv[gp->vi].p;
456         const float *vj = fp->vv[gp->vj].p;
457         const float *vk = fp->vv[gp->vk].p;
458
459         glTexCoord2f(vi[0], vi[2]);
460         glVertex3fv(vi);
461
462         glTexCoord2f(vj[0], vj[2]);
463         glVertex3fv(vj);
464
465         glTexCoord2f(vk[0], vk[2]);
466         glVertex3fv(vk);
467     }
468 }
469
470 static void sol_shad_lump(const struct s_file *fp,
471                           const struct s_lump *lp, int mi)
472 {
473     int i;
474
475     for (i = 0; i < lp->gc; i++)
476         sol_shad_geom(fp, fp->gv + fp->iv[lp->g0 + i], mi);
477 }
478
479 static void sol_shad_body(const struct s_file *fp,
480                           const struct s_body *bp,
481                           int fl, int decal)
482 {
483     int mi, li, gi;
484
485     if (fl & M_DECAL)
486     {
487         glEnable(GL_POLYGON_OFFSET_FILL);
488         glPolygonOffset(-1.0f, -2.0f);
489     }
490
491     glBegin(GL_TRIANGLES);
492     {
493         for (mi = 0; mi < fp->mc; mi++)
494             if ((fp->mv[mi].fl & fl) && (fp->mv[mi].fl & M_DECAL) == decal)
495             {
496                 for (li = 0; li < bp->lc; li++)
497                     sol_shad_lump(fp, fp->lv + bp->l0 + li, mi);
498                 for (gi = 0; gi < bp->gc; gi++)
499                     sol_shad_geom(fp, fp->gv + fp->iv[bp->g0 + gi], mi);
500             }
501     }
502     glEnd();
503
504     if (fl & M_DECAL)
505         glDisable(GL_POLYGON_OFFSET_FILL);
506 }
507
508 static void sol_shad_list(const struct s_file *fp,
509                           const struct s_body *bp, GLuint list)
510 {
511     float p[3];
512
513     sol_body_p(p, fp, bp->pi, bp->t);
514
515     glPushMatrix();
516     {
517         /* Translate a moving body. */
518
519         glTranslatef(p[0], p[1], p[2]);
520
521         /* Translate the shadow on a moving body. */
522
523         glMatrixMode(GL_TEXTURE);
524         {
525             glPushMatrix();
526             glTranslatef(p[0], p[2], 0.0f);
527         }
528         glMatrixMode(GL_MODELVIEW);
529
530         /* Draw the body. */
531
532         glCallList(list);
533
534         /* Pop the shadow translation. */
535
536         glMatrixMode(GL_TEXTURE);
537         {
538             glPopMatrix();
539         }
540         glMatrixMode(GL_MODELVIEW);
541     }
542     glPopMatrix();
543 }
544
545 void sol_shad(const struct s_file *fp)
546 {
547     int bi;
548
549     /* Render all shadowed geometry. */
550
551     glDepthMask(GL_FALSE);
552     {
553         for (bi = 0; bi < fp->bc; bi++)
554             if (fp->bv[bi].sl)
555                 sol_shad_list(fp, fp->bv + bi, fp->bv[bi].sl);
556     }
557     glDepthMask(GL_TRUE);
558 }
559
560 /*---------------------------------------------------------------------------*/
561
562 static void sol_load_objects(struct s_file *fp, int s)
563 {
564     int i;
565
566     /* Here we sort geometry into display lists by material type. */
567
568     for (i = 0; i < fp->bc; i++)
569     {
570         struct s_body *bp = fp->bv + i;
571
572         int on = sol_enum_body(fp, bp, M_OPAQUE);
573         int tn = sol_enum_body(fp, bp, M_TRANSPARENT);
574         int rn = sol_enum_body(fp, bp, M_REFLECTIVE);
575         int dn = sol_enum_body(fp, bp, M_DECAL);
576
577         /* Draw all opaque geometry, decals last. */
578
579         if (on)
580         {
581             fp->bv[i].ol = glGenLists(1);
582
583             glNewList(fp->bv[i].ol, GL_COMPILE);
584             {
585                 const struct s_mtrl *mp = &default_mtrl;
586
587                 mp = sol_draw_body(fp, fp->bv + i, mp, M_OPAQUE, 0);
588                 mp = sol_draw_body(fp, fp->bv + i, mp, M_OPAQUE, M_DECAL);
589                 mp = sol_draw_mtrl(fp, &default_mtrl, mp);
590             }
591             glEndList();
592         }
593         else fp->bv[i].ol = 0;
594
595         /* Draw all translucent geometry, decals first. */
596
597         if (tn)
598         {
599             fp->bv[i].tl = glGenLists(1);
600
601             glNewList(fp->bv[i].tl, GL_COMPILE);
602             {
603                 const struct s_mtrl *mp = &default_mtrl;
604
605                 mp = sol_draw_body(fp, fp->bv + i, mp, M_TRANSPARENT, M_DECAL);
606                 mp = sol_draw_body(fp, fp->bv + i, mp, M_TRANSPARENT, 0);
607                 mp = sol_draw_mtrl(fp, &default_mtrl, mp);
608             }
609             glEndList();
610         }
611         else fp->bv[i].tl = 0;
612
613         /* Draw all reflective geometry. */
614
615         if (rn)
616         {
617             fp->bv[i].rl = glGenLists(1);
618
619             glNewList(fp->bv[i].rl, GL_COMPILE);
620             {
621                 const struct s_mtrl *mp = &default_mtrl;
622
623                 mp = sol_draw_body(fp, fp->bv + i, mp, M_REFLECTIVE, 0);
624                 mp = sol_draw_mtrl(fp, &default_mtrl, mp);
625             }
626             glEndList();
627         }
628         else fp->bv[i].rl = 0;
629
630         /* Draw all shadowed geometry. */
631
632         if (s && (on || rn))
633         {
634             fp->bv[i].sl = glGenLists(1);
635
636             glNewList(fp->bv[i].sl, GL_COMPILE);
637             {
638                 if (on) sol_shad_body(fp, fp->bv + i, M_OPAQUE, 0);
639                 if (rn) sol_shad_body(fp, fp->bv + i, M_REFLECTIVE, 0);
640                 if (dn) sol_shad_body(fp, fp->bv + i, M_OPAQUE, M_DECAL);
641             }
642             glEndList();
643         }
644         else fp->bv[i].sl = 0;
645     }
646 }
647
648 static GLuint sol_find_texture(const char *name)
649 {
650     char png[MAXSTR];
651     char jpg[MAXSTR];
652
653     GLuint o;
654
655     /* Prefer a lossless copy of the texture over a lossy compression. */
656
657     strncpy(png, name, PATHMAX); strcat(png, ".png");
658     strncpy(jpg, name, PATHMAX); strcat(jpg, ".jpg");
659
660     /* Check for a PNG. */
661
662     if ((o = make_image_from_file(png)))
663         return o;
664
665     /* Check for a JPG. */
666
667     if ((o = make_image_from_file(jpg)))
668         return o;
669
670     return 0;
671 }
672
673 static void sol_load_textures(struct s_file *fp)
674 {
675     int i;
676
677     /* Load the image referenced by each material. */
678
679     for (i = 0; i < fp->mc; i++)
680         if ((fp->mv[i].o = sol_find_texture(_(fp->mv[i].f))))
681         {
682             /* Set the texture to clamp or repeat based on material type. */
683
684             if (fp->mv[i].fl & M_CLAMPED)
685             {
686                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
687                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
688             }
689             else
690             {
691                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
692                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
693             }
694         }
695 }
696
697 /*---------------------------------------------------------------------------*/
698
699 int sol_load_gl(struct s_file *fp, const char *filename, int s)
700 {
701     if (sol_load_only_file(fp, filename))
702     {
703         sol_load_textures(fp);
704         sol_load_objects (fp, s);
705         return 1;
706     }
707     return 0;
708 }
709
710 /*---------------------------------------------------------------------------*/
711
712 void sol_free_gl(struct s_file *fp)
713 {
714     int i;
715
716     for (i = 0; i < fp->mc; i++)
717     {
718         if (glIsTexture(fp->mv[i].o))
719             glDeleteTextures(1, &fp->mv[i].o);
720     }
721
722     for (i = 0; i < fp->bc; i++)
723     {
724         if (glIsList(fp->bv[i].ol))
725             glDeleteLists(fp->bv[i].ol, 1);
726         if (glIsList(fp->bv[i].tl))
727             glDeleteLists(fp->bv[i].tl, 1);
728         if (glIsList(fp->bv[i].rl))
729             glDeleteLists(fp->bv[i].rl, 1);
730     }
731
732     sol_free(fp);
733 }
734
735 /*---------------------------------------------------------------------------*/