~macslow/gl-cairo-aatrick/trunk

« back to all changes in this revision

Viewing changes to opengl.c

  • Committer: macslow
  • Author(s): Mirco Müller
  • Date: 2009-12-01 08:50:53 UTC
  • Revision ID: mirco@hal9000.-20091201085053-0725rj6kuckdppj6
Cleaned up code a bit. Added non-FBO (thus slow) texture-blur.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <gtk/gtkgl.h>
20
20
#include <gdk/gdkx.h>
21
21
#include <GL/gl.h>
 
22
#include <GL/glext.h>
22
23
#include <GL/glu.h>
23
24
#include <GL/glx.h>
24
25
 
25
 
#include "shaders.h"
 
26
/*#include "shaders.h"*/
26
27
#include "cairo-utils.h"
27
28
 
28
29
#define Z_NEAR  1.0f
30
31
#define FOVY   20.0f
31
32
 
32
33
gboolean g_bHasShaders = FALSE;
33
 
GLuint g_auiFragProgs[3] = {0, 0, 0};
34
 
GLuint g_auiTextureIds[3] = {0, 0, 0};
 
34
GLuint g_auiFragProgs[6] = {0, 0, 0, 0, 0, 0};
 
35
Texture* g_apTextures[6];
35
36
Texture* g_apTextTextures[3];
36
37
 
 
38
/*typedef GLvoid
 
39
(*glActiveTextureFunc) (GLenum);
 
40
 
 
41
typedef GLvoid
 
42
(*glMultiTexCoord2fARBFunc) (GLenum, GLfloat, GLfloat);
 
43
 
 
44
glActiveTextureFunc glActiveTexture = 0;
 
45
glMultiTexCoord2fARBFunc glMultiTexCoord2fARB = 0;*/
 
46
 
37
47
typedef GLvoid
38
48
(*glXSwapIntervalSGIFunc) (GLint);
39
49
 
40
50
typedef GLvoid
41
51
(*glXSwapIntervalMESAFunc) (GLint);
42
52
 
 
53
/*void
 
54
opengl_enable_multitexture (void)
 
55
{
 
56
        const gchar* pcDummy = NULL;
 
57
 
 
58
        pcDummy = glXQueryExtensionsString (GDK_DISPLAY_XDISPLAY
 
59
                                            (gdk_display_get_default ()),
 
60
                                            0);
 
61
        if (g_strrstr (pcDummy, "GL_ARB_multitexture") != NULL)
 
62
        {
 
63
                glActiveTexture = (glActiveTextureFunc)
 
64
                        gdk_gl_get_proc_address ("glActiveTexture");
 
65
                if (!glActiveTexture)
 
66
                        g_print ("Could not get glActiveTexture()\n");
 
67
 
 
68
                glMultiTexCoord2fARB = (glMultiTexCoord2fARBFunc)
 
69
                        gdk_gl_get_proc_address ("glMultiTexCoord2fARB");
 
70
                if (!glMultiTexCoord2fARB)
 
71
                        g_print ("Could not get glMultiTexCoord2fARB()\n");
 
72
        }
 
73
}*/
 
74
 
 
75
GLuint
 
76
upload_program (GLenum iTarget,   /* either vertex- or fragment-target    */
 
77
                gchar* pcFilename /* full path/filename to shader-program */)
 
78
{
 
79
        GLuint uiProgramId = 0;
 
80
        gchar* pcBuffer = NULL;
 
81
        const gsize iBufferSize = 16 * 1024; /* FIXME */
 
82
        gsize iLength = 0;
 
83
        GError* pError = NULL;
 
84
        GLint iErrorPos = 0;
 
85
        GLint iIsNative = 0;
 
86
 
 
87
        /* make sure the filename is valid */
 
88
        g_assert (pcFilename != NULL);
 
89
 
 
90
        /* allocate new handle for shader-program */
 
91
        glGenProgramsARB (1, &uiProgramId);
 
92
        if (uiProgramId == 0)
 
93
        {
 
94
                g_print ("Could not generate shader-handle for \"%s\"!\n",
 
95
                         pcFilename);
 
96
                return 0;
 
97
        }
 
98
 
 
99
        /* allocate buffer for shader-source */
 
100
        pcBuffer = (gchar*) g_malloc0 (iBufferSize);
 
101
        if (!pcBuffer)
 
102
        {
 
103
                g_print ("Error allocating buffer for \"%s\" shader!\n",
 
104
                         pcFilename);
 
105
                glDeleteProgramsARB (1, &uiProgramId);
 
106
                return 0;
 
107
        }
 
108
 
 
109
        /* read shader-file into buffer */
 
110
        if (!g_file_get_contents (pcFilename,
 
111
                                  &pcBuffer,
 
112
                                  &iLength,
 
113
                                  &pError))
 
114
        {
 
115
                g_print ("Could read shader-file \"%s\"!\n", pcFilename);
 
116
                g_free (pcBuffer);
 
117
                glDeleteProgramsARB (1, &uiProgramId);          
 
118
                return 0;
 
119
        }
 
120
 
 
121
        /* upload the shader-source to GL */
 
122
        glBindProgramARB (iTarget, uiProgramId);
 
123
        glProgramStringARB (iTarget,
 
124
                            GL_PROGRAM_FORMAT_ASCII_ARB,
 
125
                            iLength,
 
126
                            pcBuffer);
 
127
 
 
128
        /* free buffer for shader-source */
 
129
        g_free (pcBuffer);
 
130
 
 
131
        /* get any errors */
 
132
        glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &iErrorPos);
 
133
        glGetProgramivARB (iTarget,
 
134
                           GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB,
 
135
                           &iIsNative);
 
136
 
 
137
        /* check for errors */
 
138
        if ((iErrorPos == -1) && (iIsNative == 1))
 
139
                return uiProgramId;
 
140
        else
 
141
        {
 
142
                g_print ("Syntax/limit-error encountered in shader \"%s\"!\n\n",
 
143
                         pcFilename);
 
144
                g_print ("Found error:\n\033[31m%s\033[0m\n",
 
145
                         glGetString (GL_PROGRAM_ERROR_STRING_ARB));
 
146
                glDeleteProgramsARB (1, &uiProgramId);          
 
147
                return 0;
 
148
        }
 
149
}
 
150
 
43
151
/* enable (opengl_enable_vsync (2)) or disable (opengl_enable_vsync (0))
44
152
** the synchronization of the GL-rendering to the vblank of the display, for
45
153
** nice smooth graphics... you don't want to leave home without it;
271
379
/* very handy to "just quickly" load an image-file from disk and create a GL
272
380
** texture-object from it; note though that you have to know if the texture is
273
381
** pot or npot and set the iTarget (GL_TEXTURE_1D, GL_TEXTURE_2D... etc.)
274
 
** accordingly; for this particular case some special beautifying actions are
275
 
** performed on the image in memory... alpha-channel is added if needed and its
276
 
** border is trimmed a bit for some nice aa-tricks (that's what's bTrim for) */
277
 
GLuint
278
 
opengl_upload_texture (GLenum iTarget,    /* GL texture-target to use    */
279
 
                       gchar* pcFilename, /* full path/filename of image */
280
 
                       gboolean bTrim     /* trim or don't trim edges    */)
 
382
** accordingly */
 
383
Texture*
 
384
opengl_upload_texture (GLuint   uiUnit,     /* GL multi-texture unit to use  */
 
385
                       gchar*   pcFilename, /* full path/filename of image   */
 
386
                       gboolean bBlur,      /* blur image or not via CPU     */
 
387
                       gboolean bGlow       /* create glow image via CPU     */)
281
388
{
282
 
        GLuint uiTextureId = 0;
283
 
        GdkPixbuf* pSrcPixbuf = NULL;
284
 
        GdkPixbuf* pNewPixbuf = NULL;
285
 
        GError* pError = NULL;
286
 
        gint iBitsPerChannel = 0;
287
 
        gint iWidth = 0;
288
 
        gint iHeight = 0;
289
 
        guchar* pucPixelBuffer = NULL;
290
 
        gint iChannels = 0;
 
389
        GLuint     uiTextureId     = 0;
 
390
        GdkPixbuf* pSrcPixbuf      = NULL;
 
391
        GError*    pError          = NULL;
 
392
        gint       iBitsPerChannel = 0;
 
393
        gint       iWidth          = 0;
 
394
        gint       iHeight         = 0;
 
395
        guchar*    pucPixelBuffer  = NULL;
 
396
        gint       iChannels       = 0;
 
397
        guchar*    pucGlowBuffer   = NULL;
 
398
        gint       iGlowWidth      = 0;
 
399
        gint       iGlowHeight     = 0;
 
400
        Texture*   pTexture        = NULL;
291
401
 
292
402
        /* sanity check */
293
403
        g_assert (pcFilename != NULL);
294
404
 
 
405
        /* create a texture-object */
 
406
        pTexture = (Texture*) g_malloc0 (sizeof (Texture));
 
407
        if (!pTexture)
 
408
                return NULL;
 
409
 
295
410
        /* create a GL texture-handle */
296
411
        glGenTextures (1, &uiTextureId);
297
412
        if (uiTextureId == 0)
298
 
                return 0;
 
413
        {
 
414
                g_free ((gpointer) pTexture);
 
415
                return NULL;
 
416
        }
299
417
 
300
418
        /* load the image from disk */
301
419
        pSrcPixbuf = gdk_pixbuf_new_from_file (pcFilename, &pError);
302
420
        if (pSrcPixbuf == NULL)
303
421
        {
 
422
                g_free ((gpointer) pTexture);
304
423
                glDeleteTextures (1, &uiTextureId);
305
 
                return 0;
 
424
                return NULL;
306
425
        }
307
426
 
308
427
        /* only allow 8 bit per color-component */
310
429
        if (iBitsPerChannel != 8)
311
430
        {
312
431
                g_object_unref (pSrcPixbuf);
313
 
                glDeleteTextures (1, &uiTextureId);
314
 
                return 0;
315
 
        }
316
 
 
317
 
        /* add an alpha-channel if not already present and user wants to trim */
318
 
        if (!gdk_pixbuf_get_has_alpha (pSrcPixbuf) && bTrim)
319
 
                pNewPixbuf = gdk_pixbuf_add_alpha (pSrcPixbuf, FALSE, 0, 0, 0);
320
 
        else
321
 
                pNewPixbuf = gdk_pixbuf_copy (pSrcPixbuf);
322
 
 
323
 
        /* the source pixbuf is no longer needed */
324
 
        g_object_unref (pSrcPixbuf);
325
 
 
326
 
        /* check if the new pixbuf was created successfully */
327
 
        if (pNewPixbuf == NULL)
328
 
        {
329
 
                glDeleteTextures (1, &uiTextureId);
330
 
                return 0;
 
432
                g_free ((gpointer) pTexture);
 
433
                glDeleteTextures (1, &uiTextureId);
 
434
                return NULL;
331
435
        }
332
436
 
333
437
        /* determine the number of components */
334
 
        iChannels = gdk_pixbuf_get_n_channels (pNewPixbuf);
 
438
        iChannels = gdk_pixbuf_get_n_channels (pSrcPixbuf);
335
439
 
336
440
        /* get hold of dimensions and pixel-data */
337
 
        iWidth = gdk_pixbuf_get_width (pNewPixbuf);
338
 
        iHeight = gdk_pixbuf_get_height (pNewPixbuf);
339
 
        pucPixelBuffer = gdk_pixbuf_get_pixels (pNewPixbuf);
 
441
        iWidth = gdk_pixbuf_get_width (pSrcPixbuf);
 
442
        iHeight = gdk_pixbuf_get_height (pSrcPixbuf);
 
443
        pucPixelBuffer = gdk_pixbuf_get_pixels (pSrcPixbuf);
 
444
 
 
445
        if (bBlur && !bGlow)
 
446
                blur (pucPixelBuffer,
 
447
                      iWidth,
 
448
                      iHeight,
 
449
                      iChannels,
 
450
                      5);
 
451
 
 
452
        if (bGlow)
 
453
                glow (pucPixelBuffer,
 
454
                      iWidth,
 
455
                      iHeight,
 
456
                      iChannels,
 
457
                      pucGlowBuffer,
 
458
                      &iGlowWidth,
 
459
                      &iGlowHeight);
 
460
 
 
461
        pTexture->uiTextureId   = uiTextureId;
 
462
        pTexture->uiUnit        = uiUnit;
 
463
 
 
464
        if (bGlow)
 
465
        {               
 
466
                pTexture->fWidth  = (GLfloat) iGlowWidth;
 
467
                pTexture->fHeight = (GLfloat) iGlowHeight;
 
468
        }
 
469
        else
 
470
        {
 
471
                pTexture->fWidth  = (GLfloat) iWidth;
 
472
                pTexture->fHeight = (GLfloat) iHeight;
 
473
        }
 
474
 
 
475
        pTexture->iTarget       = opengl_what_texture_target (pTexture->fWidth,
 
476
                                                              pTexture->fHeight);
 
477
        pTexture->iBufferSize   = 0;
 
478
        pTexture->pucBufferData = NULL;
 
479
 
 
480
        pTexture->fMinS = 0.0f;
 
481
        pTexture->fMinT = 0.0f;
 
482
        pTexture->fMaxS = (pTexture->iTarget == GL_TEXTURE_2D) ? 1.0f : pTexture->fWidth;
 
483
        pTexture->fMaxT = (pTexture->iTarget == GL_TEXTURE_2D) ? 1.0f : pTexture->fHeight;
340
484
 
341
485
        /* see if the texture would fit */
342
 
        if (!opengl_texture_proxy_check (iTarget,
 
486
        if (!opengl_texture_proxy_check (pTexture->iTarget,
343
487
                                         iChannels,
344
488
                                         (iChannels == 4) ? GL_RGBA : GL_RGB,
 
489
                                         (GLint) pTexture->fWidth,
 
490
                                         (GLint) pTexture->fHeight))
 
491
        {
 
492
                if (pucGlowBuffer)
 
493
                        g_free ((gpointer) pucGlowBuffer);
 
494
 
 
495
                g_object_unref (pSrcPixbuf);
 
496
                g_free ((gpointer) pTexture);
 
497
                glDeleteTextures (1, &pTexture->uiTextureId);
 
498
                return NULL;
 
499
        }
 
500
 
 
501
        /* finally create the GL texture-object */
 
502
        glActiveTexture (pTexture->uiUnit);
 
503
        glBindTexture (pTexture->iTarget, pTexture->uiTextureId);
 
504
        glTexParameteri (pTexture->iTarget,
 
505
                         GL_TEXTURE_MIN_FILTER,
 
506
                         GL_LINEAR);
 
507
        glTexParameteri (pTexture->iTarget,
 
508
                         GL_TEXTURE_MAG_FILTER,
 
509
                         GL_LINEAR);
 
510
        if (bGlow)
 
511
                glTexImage2D (pTexture->iTarget,
 
512
                              0,
 
513
                              iChannels,
 
514
                              (GLsizei) pTexture->fWidth,
 
515
                              (GLsizei) pTexture->fHeight,
 
516
                              0,
 
517
                              (iChannels == 4) ? GL_RGBA : GL_RGB,
 
518
                              GL_UNSIGNED_BYTE,
 
519
                              pucGlowBuffer);
 
520
        else
 
521
                glTexImage2D (pTexture->iTarget,
 
522
                              0,
 
523
                              iChannels,
 
524
                              (GLsizei) pTexture->fWidth,
 
525
                              (GLsizei) pTexture->fHeight,
 
526
                              0,
 
527
                              (iChannels == 4) ? GL_RGBA : GL_RGB,
 
528
                              GL_UNSIGNED_BYTE,
 
529
                              pucPixelBuffer);
 
530
 
 
531
        g_object_unref (pSrcPixbuf);
 
532
 
 
533
        if (pucGlowBuffer)
 
534
                g_free ((gpointer) pucGlowBuffer);
 
535
 
 
536
        return pTexture;
 
537
}
 
538
 
 
539
Texture*
 
540
opengl_upload_mask (GLenum iTarget, /* GL texture-target to use     */
 
541
                    GLuint uiUnit,  /* GL multi-texture unit to use */
 
542
                    GLint iWidth,   /* width of mask texture        */
 
543
                    GLint iHeight   /* height of mask texture       */)
 
544
{
 
545
        GLuint   uiTextureId    = 0;
 
546
        guchar*  pucPixelBuffer = NULL;
 
547
        Texture* pTexture       = NULL;
 
548
        gint     i;
 
549
 
 
550
        /* create a texture-object */
 
551
        pTexture = (Texture*) g_malloc0 (sizeof (Texture));
 
552
        if (!pTexture)
 
553
                return NULL;
 
554
 
 
555
        /* create a GL texture-handle */
 
556
        glGenTextures (1, &uiTextureId);
 
557
        if (uiTextureId == 0)
 
558
        {
 
559
                g_free ((gpointer) pTexture);
 
560
                return NULL;
 
561
        }
 
562
 
 
563
        /* see if the texture would fit */
 
564
        if (!opengl_texture_proxy_check (iTarget,
 
565
                                         4,
 
566
                                         GL_RGBA,
345
567
                                         iWidth,
346
568
                                         iHeight))
347
569
        {
348
 
                g_object_unref (pNewPixbuf);
349
 
                glDeleteTextures (1, &uiTextureId);
350
 
                return 0;
351
 
        }
352
 
 
353
 
        /* the MacSlow-ish aa-trick */
354
 
        if (bTrim)
355
 
                cairo_trim_image (pucPixelBuffer,
356
 
                                  iWidth,
357
 
                                  iHeight,
358
 
                                  iWidth * 4);
 
570
                g_free ((gpointer) pTexture);
 
571
                glDeleteTextures (1, &uiTextureId);
 
572
                return NULL;
 
573
        }
 
574
 
 
575
        /* create pixel-buffer */
 
576
        pucPixelBuffer = (guchar*) g_malloc0 (iWidth * iHeight * 4);
 
577
        if (!pucPixelBuffer)
 
578
        {
 
579
                g_free ((gpointer) pTexture);
 
580
                glDeleteTextures (1, &uiTextureId);
 
581
                return NULL;
 
582
        }
 
583
 
 
584
        for (i = 0; i < iWidth * iHeight * 4; i++)
 
585
                pucPixelBuffer[i] = 255;
 
586
 
 
587
        /* create mask */
 
588
        cairo_trim_image (pucPixelBuffer,
 
589
                          iWidth,
 
590
                          iHeight,
 
591
                          iWidth * 4);
 
592
 
 
593
        pTexture->iTarget       = iTarget;
 
594
        pTexture->uiTextureId   = uiTextureId;
 
595
        pTexture->uiUnit        = uiUnit;
 
596
        pTexture->fWidth        = (GLfloat) iWidth;
 
597
        pTexture->fHeight       = (GLfloat) iHeight;
 
598
        pTexture->iBufferSize   = 0;
 
599
        pTexture->pucBufferData = NULL;
359
600
 
360
601
        /* finally create the GL texture-object */
361
 
        glBindTexture (iTarget, uiTextureId);   
362
 
        glTexParameteri (iTarget,
 
602
        glActiveTexture (pTexture->uiUnit);
 
603
        glBindTexture (pTexture->iTarget, pTexture->uiTextureId);       
 
604
        glTexParameteri (pTexture->iTarget,
363
605
                         GL_TEXTURE_MIN_FILTER,
364
606
                         GL_LINEAR);
365
 
        glTexParameteri (iTarget,
 
607
        glTexParameteri (pTexture->iTarget,
366
608
                         GL_TEXTURE_MAG_FILTER,
367
609
                         GL_LINEAR);
368
 
        glTexImage2D (iTarget,
369
 
                      0,
370
 
                      iChannels,
371
 
                      iWidth,
372
 
                      iHeight,
373
 
                      0,
374
 
                      (iChannels == 4) ? GL_RGBA : GL_RGB,
 
610
        glTexImage2D (pTexture->iTarget,
 
611
                      0,
 
612
                      4,
 
613
                      (GLsizei) pTexture->fWidth,
 
614
                      (GLsizei) pTexture->fHeight,
 
615
                      0,
 
616
                      GL_RGBA,
375
617
                      GL_UNSIGNED_BYTE,
376
618
                      pucPixelBuffer);
377
 
        g_object_unref (pNewPixbuf);
378
 
 
379
 
        return uiTextureId;
 
619
 
 
620
        g_free ((gpointer) pucPixelBuffer);
 
621
 
 
622
        return pTexture;
380
623
}
381
624
 
382
 
/*
383
 
**
384
 
** */
385
625
Texture*
386
626
opengl_upload_text_texture (gchar* pcText, /* text to render into texture    */
 
627
                            GLuint uiUnit, /* GL multi-texture unit to use   */
387
628
                            GLint iWidth,  /* width of win. text appears in  */
388
629
                            GLint iHeight  /* height of win. text appears in */)
389
630
{
399
640
                return NULL;
400
641
 
401
642
        /* render text into a pixel-buffer via cairo */
402
 
        pTexture = cairo_text_to_texture (pcText, iWidth, iHeight);
 
643
        pTexture = cairo_text_to_texture (pcText);
403
644
        if (!pTexture)
404
645
        {
405
646
                glDeleteTextures (1, &uiTextureId);
407
648
        }
408
649
 
409
650
        pTexture->uiTextureId = uiTextureId;
 
651
        pTexture->uiUnit = uiUnit;
410
652
 
411
653
        /* pass pixel-buffer to GL */
 
654
        glActiveTexture (pTexture->uiUnit);
412
655
        glBindTexture (pTexture->iTarget, pTexture->uiTextureId);
413
656
        glTexParameteri (pTexture->iTarget,
414
657
                         GL_TEXTURE_MIN_FILTER,
428
671
 
429
672
        /* get rid of resources no longer needed, buffer was allocated in
430
673
        ** cairo_text_to_texture() */
431
 
        g_slice_free1 (pTexture->iBufferSize,
432
 
                       (gpointer) pTexture->pucBufferData);
 
674
        g_free ((gpointer) pTexture->pucBufferData);
433
675
 
434
676
        /* pass valid texture-handle to caller */
435
677
        return pTexture;
436
678
}
437
679
 
 
680
void
 
681
opengl_delete_texture (Texture* pTexture /* texture to delete */)
 
682
{
 
683
        if (!pTexture);
 
684
                return;
 
685
 
 
686
        glDeleteTextures (1, &pTexture->uiTextureId);
 
687
 
 
688
        if (pTexture->pucBufferData)
 
689
                g_free ((gpointer) pTexture->pucBufferData);
 
690
 
 
691
        g_free ((gpointer) pTexture);
 
692
}
 
693
 
438
694
/* just to make the background less boring I've implemented a simple
439
695
** checker-board painting function; remember: values to pass differ greatly
440
696
** depending on the kind of projection-matrix you've set up */
490
746
{
491
747
        glBegin (GL_QUADS);
492
748
 
493
 
        /* top third, darker grey to white */
494
 
        glColor3f (0.85f, 0.85f, 0.85f);
495
 
        glVertex3f (fStartX, fStartY, 0.0f);
496
 
        glColor3f (0.85f, 0.85f, 0.85f);
497
 
        glVertex3f (fStartX + fWidth, fStartY, 0.0f);
498
 
        glColor3f (1.0f, 1.0f, 1.0f);
499
 
        glVertex3f (fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
500
 
        glColor3f (1.0f, 1.0f, 1.0f);
501
 
        glVertex3f (fStartX, fStartY + fHeight / 3.0f, 0.0f);
502
 
 
503
 
        /* middle third, just plain white */
504
 
        glColor3f (1.0f, 1.0f, 1.0f);
505
 
        glVertex3f (fStartX, fStartY + fHeight / 3.0f, 0.0f);
506
 
        glVertex3f (fStartX + fWidth, fStartY + fHeight / 3.0f, 0.0f);
507
 
        glVertex3f (fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
508
 
        glVertex3f (fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
509
 
 
510
 
        /* bottom third, white to lighter grey */
511
 
        glColor3f (1.0f, 1.0f, 1.0f);
512
 
        glVertex3f (fStartX, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
513
 
        glColor3f (1.0f, 1.0f, 1.0f);
514
 
        glVertex3f (fStartX + fWidth, fStartY + 2.0f * fHeight / 3.0f, 0.0f);
515
 
        glColor3f (0.62f, 0.66f, 0.69f);
516
 
        glVertex3f (fStartX + fWidth, fStartY + fHeight, 0.0f);
517
 
        glColor3f (0.62f, 0.66f, 0.69f);
518
 
        glVertex3f (fStartX, fStartY + fHeight, 0.0f);
 
749
        /* top half, black */
 
750
        glColor3f (0.0f, 0.0f, 0.0f);
 
751
        glVertex3f (fStartX,          fStartY + fHeight,        0.0f);
 
752
        glVertex3f (fStartX + fWidth, fStartY + fHeight,        0.0f);
 
753
        glVertex3f (fStartX + fWidth, fStartY + fHeight / 2.0f, 0.0f);
 
754
        glVertex3f (fStartX,          fStartY + fHeight / 2.0f, 0.0f);
 
755
 
 
756
        /* bottom half, black to dark grey */
 
757
        glColor3f (0.0f, 0.0f, 0.0f);
 
758
        glVertex3f (fStartX + fWidth, fStartY + fHeight / 2.0f, 0.0f);
 
759
        glVertex3f (fStartX,          fStartY + fHeight / 2.0f, 0.0f);
 
760
        glColor3f (0.3f, 0.3f, 0.3f);
 
761
        glVertex3f (fStartX,          fStartY,                  0.0f);
 
762
        glVertex3f (fStartX + fWidth, fStartY,                  0.0f);
 
763
 
519
764
        glEnd ();
520
765
}
521
766
 
528
773
        GLfloat afLightDiffuse[4] = {0.76f, 0.75f, 0.65f, 1.0f};
529
774
 
530
775
        /* set some GL-states */
531
 
        glClearColor (0.0f, 0.0f, 1.0f, 1.0f);
 
776
        glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
532
777
        glColor4f (1.0f, 1.0f, 1.0f, 0.0f);
533
778
        glEnable (GL_TEXTURE_2D);
534
779
        glEnable (GL_BLEND);
549
794
        glTranslatef (0.0f, 0.0f, -Z_NEAR);
550
795
 
551
796
        /* try to find and initialize programmable shading capabilities */
552
 
        if (setup_shader_callbacks ())
553
 
        {
 
797
        /*if (setup_shader_callbacks ())
 
798
        {*/
554
799
                g_bHasShaders = TRUE;
555
800
                glEnable (GL_FRAGMENT_PROGRAM_ARB);
556
801
                g_auiFragProgs[0] = upload_program (GL_FRAGMENT_PROGRAM_ARB,
559
804
                                                    "texture-2d.frag");
560
805
                g_auiFragProgs[2] = upload_program (GL_FRAGMENT_PROGRAM_ARB,
561
806
                                                    "texture-rect.frag");
562
 
        }
 
807
                g_auiFragProgs[3] = upload_program (GL_FRAGMENT_PROGRAM_ARB,
 
808
                                                    "texture-blur-2d.frag");
 
809
                g_auiFragProgs[4] = upload_program (GL_FRAGMENT_PROGRAM_ARB,
 
810
                                                    "texture-emboss-2d.frag");
 
811
                g_auiFragProgs[5] = upload_program (GL_FRAGMENT_PROGRAM_ARB,
 
812
                                                    "texture-sobel-2d.frag");
 
813
        /*}*/
 
814
 
 
815
        /* setup multi-texture related calls */
 
816
        /*opengl_enable_multitexture ();*/
563
817
 
564
818
        /* switch on sync-to-vblank*/
565
 
        opengl_enable_vsync (2);
 
819
        opengl_enable_vsync (1);
566
820
 
567
821
        /* load and setup needed texture-resources */
568
 
        g_auiTextureIds[0] = opengl_upload_texture (GL_TEXTURE_2D,
569
 
                                                    "zebra.png",
570
 
                                                    TRUE);
571
 
        g_auiTextureIds[1] = opengl_upload_texture (GL_TEXTURE_2D,
572
 
                                                    "zebra.png",
573
 
                                                    FALSE);
574
 
        g_auiTextureIds[2] = opengl_upload_texture (GL_TEXTURE_2D,
575
 
                                                    "zebra-trimmed.png",
576
 
                                                    FALSE);
 
822
        g_apTextures[0] = opengl_upload_texture (GL_TEXTURE0,
 
823
                                                 "ui-shot.png",
 
824
                                                 FALSE,
 
825
                                                 FALSE);
 
826
        g_apTextures[1] = opengl_upload_texture (GL_TEXTURE0,
 
827
                                                 "ui-shot.png",
 
828
                                                 FALSE,
 
829
                                                 FALSE);
 
830
        g_apTextures[2] = opengl_upload_texture (GL_TEXTURE0,
 
831
                                                 "ui-shot.png",
 
832
                                                 FALSE,
 
833
                                                 FALSE);
 
834
        g_apTextures[3] = opengl_upload_mask (GL_TEXTURE_2D,
 
835
                                              GL_TEXTURE1,
 
836
                                              512,
 
837
                                              512);
 
838
        g_apTextures[4] = opengl_upload_texture (GL_TEXTURE0,
 
839
                                                 "ui-shot.png",
 
840
                                                 FALSE,
 
841
                                                 FALSE);
 
842
        g_apTextures[5] = opengl_upload_texture (GL_TEXTURE0,
 
843
                                                 "ui-shot.png",
 
844
                                                 FALSE,
 
845
                                                 FALSE);
577
846
 
578
 
        g_apTextTextures[0] =  opengl_upload_text_texture ("trimmed in Gimp",
579
 
                                                           iWidth,
580
 
                                                           iHeight);
581
 
        g_apTextTextures[1] =  opengl_upload_text_texture ("trimmed with cairo",
582
 
                                                           iWidth,
583
 
                                                           iHeight);
584
 
        g_apTextTextures[2] =  opengl_upload_text_texture ("untrimmed",
 
847
        g_apTextTextures[0] =  opengl_upload_text_texture ("embossed (GPU)",
 
848
                                                           GL_TEXTURE0,
 
849
                                                           iWidth,
 
850
                                                           iHeight);
 
851
        g_apTextTextures[1] =  opengl_upload_text_texture ("blurred (GPU)",
 
852
                                                           GL_TEXTURE0,
 
853
                                                           iWidth,
 
854
                                                           iHeight);
 
855
        g_apTextTextures[2] =  opengl_upload_text_texture ("edge-detect (GPU)",
 
856
                                                           GL_TEXTURE0,
585
857
                                                           iWidth,
586
858
                                                           iHeight);
587
859
}
604
876
        ** regarding this issue: remember id-software games, which are OpenGL-
605
877
        ** -based... they regenerate all their game resources if you alter the 
606
878
        ** game-resolution) */
607
 
        glDeleteTextures (3, g_auiTextureIds);
608
 
        g_auiTextureIds[0] = opengl_upload_texture (GL_TEXTURE_2D,
609
 
                                                    "zebra.png",
610
 
                                                    TRUE);
611
 
        g_auiTextureIds[1] = opengl_upload_texture (GL_TEXTURE_2D,
612
 
                                                    "zebra.png",
613
 
                                                    FALSE);
614
 
        g_auiTextureIds[2] = opengl_upload_texture (GL_TEXTURE_2D,
615
 
                                                    "zebra_trimmed.png",
616
 
                                                    FALSE);
617
 
 
618
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[0]);
619
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[1]);
620
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[2]);
621
 
        g_apTextTextures[0] =  opengl_upload_text_texture ("trimmed in Gimp",
622
 
                                                          iWidth,
623
 
                                                          iHeight);
624
 
        g_apTextTextures[1] =  opengl_upload_text_texture ("trimmed with cairo",
625
 
                                                          iWidth,
626
 
                                                          iHeight);
627
 
        g_apTextTextures[2] =  opengl_upload_text_texture ("untrimmed",
628
 
                                                          iWidth,
629
 
                                                          iHeight);
 
879
        opengl_delete_texture (g_apTextures[0]);
 
880
        opengl_delete_texture (g_apTextures[1]);
 
881
        opengl_delete_texture (g_apTextures[2]);
 
882
        opengl_delete_texture (g_apTextures[3]);
 
883
        opengl_delete_texture (g_apTextures[4]);
 
884
        g_apTextures[0] = opengl_upload_texture (GL_TEXTURE0,
 
885
                                                 "ui-shot.png",
 
886
                                                 FALSE,
 
887
                                                 FALSE);
 
888
        g_apTextures[1] = opengl_upload_texture (GL_TEXTURE0,
 
889
                                                 "ui-shot.png",
 
890
                                                 FALSE,
 
891
                                                 FALSE);
 
892
        g_apTextures[2] = opengl_upload_texture (GL_TEXTURE0,
 
893
                                                 "ui-shot.png",
 
894
                                                 FALSE,
 
895
                                                 FALSE);
 
896
        g_apTextures[3] = opengl_upload_mask (GL_TEXTURE_2D,
 
897
                                              GL_TEXTURE1,
 
898
                                              512,
 
899
                                              512);
 
900
        g_apTextures[4] = opengl_upload_texture (GL_TEXTURE0,
 
901
                                                 "ui-shot.png",
 
902
                                                 FALSE,
 
903
                                                 FALSE);
 
904
        g_apTextures[5] = opengl_upload_texture (GL_TEXTURE0,
 
905
                                                 "ui-shot.png",
 
906
                                                 FALSE,
 
907
                                                 FALSE);
 
908
        
 
909
        opengl_delete_texture (g_apTextTextures[0]);
 
910
        opengl_delete_texture (g_apTextTextures[1]);
 
911
        opengl_delete_texture (g_apTextTextures[2]);
 
912
        g_apTextTextures[0] =  opengl_upload_text_texture ("embossed (GPU)",
 
913
                                                           GL_TEXTURE0,
 
914
                                                           iWidth,
 
915
                                                           iHeight);
 
916
        g_apTextTextures[1] =  opengl_upload_text_texture ("blurred (GPU)",
 
917
                                                           GL_TEXTURE0,
 
918
                                                           iWidth,
 
919
                                                           iHeight);
 
920
        g_apTextTextures[2] =  opengl_upload_text_texture ("edge-detect (GPU)",
 
921
                                                           GL_TEXTURE0,
 
922
                                                           iWidth,
 
923
                                                           iHeight);
 
924
}
 
925
 
 
926
void
 
927
opengl_draw_textured_quad (Texture* pTexture,   /* texture to use          */
 
928
                           GLuint   uiFragProg, /* shader to use           */
 
929
                           GLfloat* pfPosition, /* position of quad        */
 
930
                           GLfloat  fAngle,     /* current rotation angle  */
 
931
                           GLfloat* pfAxis,     /* rotation-axis           */
 
932
                           gboolean bNormal,    /* normal or reflected     */
 
933
                           GLfloat  fValue      /* value to pass to shader */)
 
934
{
 
935
        GLfloat afMaterialDiffuseFrontFull[4]    = {1.0f, 1.0f, 1.0f, 1.0f};
 
936
        GLfloat afMaterialDiffuseBackFull[4]     = {0.0f, 0.16f, 0.31f, 1.0f};
 
937
        GLfloat afMaterialDiffuseFrontOff[4]     = {1.0f, 1.0f, 1.0f, 0.0f};
 
938
        GLfloat afMaterialDiffuseBackOff[4]      = {0.0f, 0.16f, 0.31f, 0.0f};
 
939
        GLfloat afMaterialDiffuseFrontQuarter[4] = {1.0f, 1.0f, 1.0f, 0.25f};
 
940
        GLfloat afMaterialDiffuseBackQuarter[4]  = {0.0f, 0.16f, 0.31f, 0.25f};
 
941
        GLfloat fPixelSize = 0.0f;
 
942
 
 
943
        /* sanity checks */
 
944
        g_assert (pTexture != NULL);
 
945
        g_assert (pfPosition != NULL);
 
946
        g_assert (pfAxis != NULL);
 
947
 
 
948
        glActiveTexture (pTexture->uiUnit);
 
949
        glEnable (pTexture->iTarget);
 
950
        glBindTexture (pTexture->iTarget, pTexture->uiTextureId);
 
951
        glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, uiFragProg);
 
952
 
 
953
        fPixelSize = 1.0f / pTexture->fWidth;
 
954
 
 
955
        glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB,
 
956
                                      0,
 
957
                                      fValue,
 
958
                                      -fValue,
 
959
                                      fPixelSize,
 
960
                                      0.0f);
 
961
 
 
962
        glPushMatrix ();
 
963
        glTranslatef (pfPosition[X], pfPosition[Y], pfPosition[Z]);
 
964
        glRotatef (fAngle, pfAxis[X], pfAxis[Y], pfAxis[Z]);
 
965
 
 
966
        glBegin (GL_QUADS);
 
967
 
 
968
        if (bNormal)
 
969
        {
 
970
                glNormal3f (0.0f, 0.0f, 1.0f);
 
971
                glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
 
972
                glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontFull);
 
973
                glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackFull);
 
974
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
975
                                      pTexture->fMinS,
 
976
                                      pTexture->fMaxT);
 
977
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
978
                                      pTexture->fMinS,
 
979
                                      pTexture->fMaxT - fPixelSize);
 
980
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
981
                                      pTexture->fMinS + fPixelSize,
 
982
                                      pTexture->fMaxT);
 
983
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
984
                                      pTexture->fMinS,
 
985
                                      pTexture->fMaxT + fPixelSize);
 
986
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
987
                                      pTexture->fMinS - fPixelSize,
 
988
                                      pTexture->fMaxT);
 
989
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
990
                                      pTexture->fMinS,
 
991
                                      pTexture->fMaxT + fPixelSize);
 
992
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
993
                                      pTexture->fMinS + fPixelSize,
 
994
                                      pTexture->fMaxT);
 
995
                glVertex3f (-1.5f, -1.525f, 0.0f);
 
996
 
 
997
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
998
                                      pTexture->fMaxS,
 
999
                                      pTexture->fMaxT);
 
1000
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1001
                                      pTexture->fMaxS,
 
1002
                                      pTexture->fMaxT - fPixelSize);
 
1003
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1004
                                      pTexture->fMaxS + fPixelSize,
 
1005
                                      pTexture->fMaxT);
 
1006
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1007
                                      pTexture->fMaxS,
 
1008
                                      pTexture->fMaxT + fPixelSize);
 
1009
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1010
                                      pTexture->fMaxS - fPixelSize,
 
1011
                                      pTexture->fMaxT);
 
1012
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1013
                                      pTexture->fMaxS,
 
1014
                                      pTexture->fMaxT + fPixelSize);
 
1015
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1016
                                      pTexture->fMaxS + fPixelSize,
 
1017
                                      pTexture->fMaxT);
 
1018
                glVertex3f ( 1.5f, -1.525f, 0.0f);
 
1019
 
 
1020
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1021
                                      pTexture->fMaxS,
 
1022
                                      pTexture->fMinT);
 
1023
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1024
                                      pTexture->fMaxS,
 
1025
                                      pTexture->fMinT - fPixelSize);
 
1026
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1027
                                      pTexture->fMaxS + fPixelSize,
 
1028
                                      pTexture->fMinT);
 
1029
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1030
                                      pTexture->fMaxS,
 
1031
                                      pTexture->fMinT + fPixelSize);
 
1032
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1033
                                      pTexture->fMaxS - fPixelSize,
 
1034
                                      pTexture->fMinT);
 
1035
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1036
                                      pTexture->fMaxS,
 
1037
                                      pTexture->fMinT + fPixelSize);
 
1038
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1039
                                      pTexture->fMaxS + fPixelSize,
 
1040
                                      pTexture->fMinT);
 
1041
                glVertex3f ( 1.5f,  1.475f, 0.0f);
 
1042
 
 
1043
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1044
                                      pTexture->fMinS,
 
1045
                                      pTexture->fMinT);
 
1046
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1047
                                      pTexture->fMinS,
 
1048
                                      pTexture->fMinT - fPixelSize);
 
1049
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1050
                                      pTexture->fMinS + fPixelSize,
 
1051
                                      pTexture->fMinT);
 
1052
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1053
                                      pTexture->fMinS,
 
1054
                                      pTexture->fMinT + fPixelSize);
 
1055
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1056
                                      pTexture->fMinS - fPixelSize,
 
1057
                                      pTexture->fMinT);
 
1058
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1059
                                      pTexture->fMinS,
 
1060
                                      pTexture->fMinT + fPixelSize);
 
1061
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1062
                                      pTexture->fMinS + fPixelSize,
 
1063
                                      pTexture->fMinT);
 
1064
                glVertex3f (-1.5f,  1.475f, 0.0f);
 
1065
        }
 
1066
        else
 
1067
        {
 
1068
                glNormal3f (0.0f, 0.0f, 1.0f);
 
1069
                glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
 
1070
                glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontOff);
 
1071
                glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackOff);
 
1072
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1073
                                      pTexture->fMinS,
 
1074
                                      pTexture->fMaxT * 0.5f);
 
1075
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1076
                                      pTexture->fMinS,
 
1077
                                      pTexture->fMaxT * 0.5f - fPixelSize);
 
1078
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1079
                                      pTexture->fMinS + fPixelSize,
 
1080
                                      pTexture->fMaxT * 0.5f);
 
1081
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1082
                                      pTexture->fMinS,
 
1083
                                      pTexture->fMaxT * 0.5f + fPixelSize);
 
1084
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1085
                                      pTexture->fMinS - fPixelSize,
 
1086
                                      pTexture->fMaxT * 0.5f);
 
1087
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1088
                                      pTexture->fMinS,
 
1089
                                      pTexture->fMaxT * 0.5f + fPixelSize);
 
1090
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1091
                                      pTexture->fMinS + fPixelSize,
 
1092
                                      pTexture->fMaxT * 0.5f);
 
1093
                glVertex3f (-1.5f, -2.75f, 0.0f);
 
1094
 
 
1095
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1096
                                      pTexture->fMaxS,
 
1097
                                      pTexture->fMaxT * 0.5f);
 
1098
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1099
                                      pTexture->fMaxS,
 
1100
                                      pTexture->fMaxT * 0.5f - fPixelSize);
 
1101
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1102
                                      pTexture->fMaxS + fPixelSize,
 
1103
                                      pTexture->fMaxT * 0.5f);
 
1104
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1105
                                      pTexture->fMaxS,
 
1106
                                      pTexture->fMaxT * 0.5f + fPixelSize);
 
1107
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1108
                                      pTexture->fMaxS - fPixelSize,
 
1109
                                      pTexture->fMaxT * 0.5f);
 
1110
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1111
                                      pTexture->fMaxS,
 
1112
                                      pTexture->fMaxT * 0.5f + fPixelSize);
 
1113
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1114
                                      pTexture->fMaxS + fPixelSize,
 
1115
                                      pTexture->fMaxT * 0.5f);
 
1116
                glVertex3f ( 1.5f, -2.75f, 0.0f);
 
1117
 
 
1118
                glColor4f (1.0f, 1.0f, 1.0f, 0.25f);
 
1119
                glMaterialfv (GL_FRONT,
 
1120
                              GL_DIFFUSE,
 
1121
                              afMaterialDiffuseFrontQuarter);
 
1122
                glMaterialfv (GL_BACK,
 
1123
                              GL_DIFFUSE,
 
1124
                              afMaterialDiffuseBackQuarter);
 
1125
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1126
                                      pTexture->fMaxS,
 
1127
                                      pTexture->fMaxT);
 
1128
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1129
                                      pTexture->fMaxS,
 
1130
                                      pTexture->fMaxT - fPixelSize);
 
1131
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1132
                                      pTexture->fMaxS + fPixelSize,
 
1133
                                      pTexture->fMaxT);
 
1134
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1135
                                      pTexture->fMaxS,
 
1136
                                      pTexture->fMaxT + fPixelSize);
 
1137
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1138
                                      pTexture->fMaxS - fPixelSize,
 
1139
                                      pTexture->fMaxT);
 
1140
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1141
                                      pTexture->fMaxS,
 
1142
                                      pTexture->fMaxT + fPixelSize);
 
1143
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1144
                                      pTexture->fMaxS + fPixelSize,
 
1145
                                      pTexture->fMaxT);
 
1146
                glVertex3f ( 1.5f, -1.475f, 0.0f);
 
1147
 
 
1148
                glMultiTexCoord2fARB (pTexture->uiUnit,
 
1149
                                      pTexture->fMinS,
 
1150
                                      pTexture->fMaxT);
 
1151
                glMultiTexCoord2fARB (GL_TEXTURE2,
 
1152
                                      pTexture->fMinS,
 
1153
                                      pTexture->fMaxT - fPixelSize);
 
1154
                glMultiTexCoord2fARB (GL_TEXTURE3,
 
1155
                                      pTexture->fMinS + fPixelSize,
 
1156
                                      pTexture->fMaxT);
 
1157
                glMultiTexCoord2fARB (GL_TEXTURE4,
 
1158
                                      pTexture->fMinS,
 
1159
                                      pTexture->fMaxT + fPixelSize);
 
1160
                glMultiTexCoord2fARB (GL_TEXTURE5,
 
1161
                                      pTexture->fMinS - fPixelSize,
 
1162
                                      pTexture->fMaxT);
 
1163
                glMultiTexCoord2fARB (GL_TEXTURE6,
 
1164
                                      pTexture->fMinS,
 
1165
                                      pTexture->fMaxT + fPixelSize);
 
1166
                glMultiTexCoord2fARB (GL_TEXTURE7,
 
1167
                                      pTexture->fMinS + fPixelSize,
 
1168
                                      pTexture->fMaxT);
 
1169
                glVertex3f (-1.5f, -1.475f, 0.0f);
 
1170
        }
 
1171
 
 
1172
        glEnd ();
 
1173
        glPopMatrix ();
 
1174
        glDisable (pTexture->iTarget);
 
1175
}
 
1176
 
 
1177
void
 
1178
opengl_blur_pass (Texture*      pSrcTexture,    /* texture to read from      */
 
1179
                  Texture*      pDstTexture,    /* texture to write to       */
 
1180
                  GLuint        uiFragProg,     /* shader to use             */
 
1181
                  GLfloat       fDeviation,     /* std. deviatino to use     */
 
1182
                  PassDirection direction,      /* do which pass of the blur */
 
1183
                  GLint         iWindowWidth,   /* width of window/context   */
 
1184
                  GLint         iWindowHeight   /* height of window/context  */)
 
1185
{
 
1186
        static GLfloat fPixelSize = 0.0f;
 
1187
        static GLfloat afKernel[12];
 
1188
        static GLfloat aafVertices[4][3];
 
1189
 
 
1190
        opengl_change_projection (TRUE, iWindowWidth, iWindowHeight);
 
1191
        glDisable (GL_LIGHTING);
 
1192
        glEnable (pSrcTexture->iTarget);
 
1193
        glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, uiFragProg);
 
1194
        glActiveTexture (pSrcTexture->uiUnit);
 
1195
        glBindTexture (pSrcTexture->iTarget,
 
1196
                       pSrcTexture->uiTextureId);
 
1197
 
 
1198
        compute_1d_kernel (5, fDeviation, afKernel);
 
1199
 
 
1200
        if (direction == VERTICAL_PASS)
 
1201
        {
 
1202
                fPixelSize = 1.0f / pSrcTexture->fHeight;
 
1203
 
 
1204
                aafVertices[0][X] = 0.0f;
 
1205
                aafVertices[0][Y] = pSrcTexture->fHeight;
 
1206
                aafVertices[0][Z] = 0.0f;
 
1207
 
 
1208
                aafVertices[1][X] = pSrcTexture->fWidth;
 
1209
                aafVertices[1][Y] = pSrcTexture->fHeight;
 
1210
                aafVertices[1][Z] = 0.0f;
 
1211
 
 
1212
                aafVertices[2][X] = pSrcTexture->fWidth;
 
1213
                aafVertices[2][Y] = 0.0f;
 
1214
                aafVertices[2][Z] = 0.0f;
 
1215
 
 
1216
                aafVertices[3][X] = 0.0f;
 
1217
                aafVertices[3][Y] = 0.0f;
 
1218
                aafVertices[3][Z] = 0.0f;
 
1219
        }
 
1220
        else if (direction == HORIZONTAL_PASS)
 
1221
        {
 
1222
                fPixelSize = 1.0f / pSrcTexture->fWidth;
 
1223
 
 
1224
                aafVertices[0][X] = 0.0f;
 
1225
                aafVertices[0][Y] = pSrcTexture->fHeight;
 
1226
                aafVertices[0][Z] = 0.0f;
 
1227
 
 
1228
                aafVertices[1][X] = pSrcTexture->fWidth;
 
1229
                aafVertices[1][Y] = pSrcTexture->fHeight;
 
1230
                aafVertices[1][Z] = 0.0f;
 
1231
 
 
1232
                aafVertices[2][X] = pSrcTexture->fWidth;
 
1233
                aafVertices[2][Y] = 0.0f;
 
1234
                aafVertices[2][Z] = 0.0f;
 
1235
 
 
1236
                aafVertices[3][X] = 0.0f;
 
1237
                aafVertices[3][Y] = 0.0f;
 
1238
                aafVertices[3][Z] = 0.0f;
 
1239
        }
 
1240
 
 
1241
        afKernel[11] = fPixelSize;
 
1242
 
 
1243
        glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB,
 
1244
                                      0,
 
1245
                                      afKernel[0],
 
1246
                                      afKernel[1],
 
1247
                                      afKernel[2],
 
1248
                                      afKernel[3]);
 
1249
        glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB,
 
1250
                                      1,
 
1251
                                      afKernel[4],
 
1252
                                      afKernel[5],
 
1253
                                      afKernel[6],
 
1254
                                      afKernel[7]);
 
1255
        glProgramLocalParameter4fARB (GL_FRAGMENT_PROGRAM_ARB,
 
1256
                                      2,
 
1257
                                      afKernel[8],
 
1258
                                      afKernel[9],
 
1259
                                      afKernel[10],
 
1260
                                      afKernel[11]);
 
1261
 
 
1262
        glPushMatrix ();
 
1263
        glTranslatef ((GLfloat) iWindowWidth / -2.0f,
 
1264
                      (GLfloat) iWindowHeight / -2.0f,
 
1265
                      0.0f);
 
1266
        glBegin (GL_QUADS);
 
1267
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
 
1268
 
 
1269
        glMultiTexCoord2fARB (GL_TEXTURE0, fPixelSize * -5.0f, 1.0f);
 
1270
        glMultiTexCoord2fARB (GL_TEXTURE1, fPixelSize * -4.0f, 1.0f);
 
1271
        glMultiTexCoord2fARB (GL_TEXTURE2, fPixelSize * -3.0f, 1.0f);
 
1272
        glMultiTexCoord2fARB (GL_TEXTURE3, fPixelSize * -2.0f, 1.0f);
 
1273
        glMultiTexCoord2fARB (GL_TEXTURE4, fPixelSize * -1.0f, 1.0f);
 
1274
        glMultiTexCoord2fARB (GL_TEXTURE5, fPixelSize *  0.0f, 1.0f);
 
1275
        glMultiTexCoord2fARB (GL_TEXTURE6, fPixelSize *  1.0f, 1.0f);
 
1276
        glMultiTexCoord2fARB (GL_TEXTURE7, fPixelSize *  2.0f, 1.0f);
 
1277
        glVertex3f (aafVertices[0][X], aafVertices[0][Y], aafVertices[0][Z]);
 
1278
 
 
1279
        glMultiTexCoord2fARB (GL_TEXTURE0, fPixelSize * -5.0f, 0.0f);
 
1280
        glMultiTexCoord2fARB (GL_TEXTURE1, fPixelSize * -4.0f, 0.0f);
 
1281
        glMultiTexCoord2fARB (GL_TEXTURE2, fPixelSize * -3.0f, 0.0f);
 
1282
        glMultiTexCoord2fARB (GL_TEXTURE3, fPixelSize * -2.0f, 0.0f);
 
1283
        glMultiTexCoord2fARB (GL_TEXTURE4, fPixelSize * -1.0f, 0.0f);
 
1284
        glMultiTexCoord2fARB (GL_TEXTURE5, fPixelSize *  0.0f, 0.0f);
 
1285
        glMultiTexCoord2fARB (GL_TEXTURE6, fPixelSize *  1.0f, 0.0f);
 
1286
        glMultiTexCoord2fARB (GL_TEXTURE7, fPixelSize *  2.0f, 0.0f);
 
1287
        glVertex3f (aafVertices[1][X], aafVertices[1][Y], aafVertices[1][Z]);
 
1288
 
 
1289
        glMultiTexCoord2fARB (GL_TEXTURE0, 1.0f + fPixelSize * -5.0f, 0.0f);
 
1290
        glMultiTexCoord2fARB (GL_TEXTURE1, 1.0f + fPixelSize * -4.0f, 0.0f);
 
1291
        glMultiTexCoord2fARB (GL_TEXTURE2, 1.0f + fPixelSize * -3.0f, 0.0f);
 
1292
        glMultiTexCoord2fARB (GL_TEXTURE3, 1.0f + fPixelSize * -2.0f, 0.0f);
 
1293
        glMultiTexCoord2fARB (GL_TEXTURE4, 1.0f + fPixelSize * -1.0f, 0.0f);
 
1294
        glMultiTexCoord2fARB (GL_TEXTURE5, 1.0f + fPixelSize *  0.0f, 0.0f);
 
1295
        glMultiTexCoord2fARB (GL_TEXTURE6, 1.0f + fPixelSize *  1.0f, 0.0f);
 
1296
        glMultiTexCoord2fARB (GL_TEXTURE7, 1.0f + fPixelSize *  2.0f, 0.0f);
 
1297
        glVertex3f (aafVertices[2][X], aafVertices[2][Y], aafVertices[2][Z]);
 
1298
 
 
1299
        glMultiTexCoord2fARB (GL_TEXTURE0, 1.0f + fPixelSize * -5.0f, 1.0f);
 
1300
        glMultiTexCoord2fARB (GL_TEXTURE1, 1.0f + fPixelSize * -4.0f, 1.0f);
 
1301
        glMultiTexCoord2fARB (GL_TEXTURE2, 1.0f + fPixelSize * -3.0f, 1.0f);
 
1302
        glMultiTexCoord2fARB (GL_TEXTURE3, 1.0f + fPixelSize *  2.0f, 1.0f);
 
1303
        glMultiTexCoord2fARB (GL_TEXTURE4, 1.0f + fPixelSize *  1.0f, 1.0f);
 
1304
        glMultiTexCoord2fARB (GL_TEXTURE5, 1.0f + fPixelSize *  0.0f, 1.0f);
 
1305
        glMultiTexCoord2fARB (GL_TEXTURE6, 1.0f + fPixelSize *  1.0f, 1.0f);
 
1306
        glMultiTexCoord2fARB (GL_TEXTURE7, 1.0f + fPixelSize *  2.0f, 1.0f);
 
1307
        glVertex3f (aafVertices[3][X], aafVertices[3][Y], aafVertices[3][Z]);
 
1308
 
 
1309
        glEnd ();
 
1310
        glPopMatrix ();
 
1311
        glDisable (pSrcTexture->iTarget);
 
1312
 
 
1313
        /* read-back the blurred image */
 
1314
        glEnable (pDstTexture->iTarget);
 
1315
        glBindTexture (pDstTexture->iTarget,
 
1316
                       pDstTexture->uiTextureId);
 
1317
        glCopyTexSubImage2D (pDstTexture->iTarget,
 
1318
                             0,
 
1319
                             0,
 
1320
                             0,
 
1321
                             0,
 
1322
                             0,
 
1323
                             pDstTexture->fWidth,
 
1324
                             pDstTexture->fHeight);
 
1325
        glDisable (pDstTexture->iTarget);
630
1326
}
631
1327
 
632
1328
/* the main action takes place here once everything is setup; this is what gets
633
1329
** called very time we force a refresh/redraw of the window */
634
1330
void
635
 
opengl_draw (GLsizei iWidth, /* current width of the GL-context  */
636
 
             GLsizei iHeight /* current height of the GL-context */)
 
1331
opengl_draw (GLsizei iWidth,  /* current width of the GL-context  */
 
1332
             GLsizei iHeight, /* current height of the GL-context */
 
1333
             GLfloat fFactor  /* some factor to use for anything  */)
637
1334
{
638
1335
        static GLfloat fAngle = 0.0f;
639
 
        GLfloat afMaterialDiffuseFrontFull[4] = {1.0f, 1.0f, 1.0f, 1.0f};
640
 
        GLfloat afMaterialDiffuseBackFull[4] = {0.0f, 0.16f, 0.31f, 1.0f};
641
 
        GLfloat afMaterialDiffuseFrontOff[4] = {1.0f, 1.0f, 1.0f, 0.0f};
642
 
        GLfloat afMaterialDiffuseBackOff[4] = {0.0f, 0.16f, 0.31f, 0.0f};
643
 
        GLfloat afMaterialDiffuseFrontQuarter[4] = {1.0f, 1.0f, 1.0f, 0.25f};
644
 
        GLfloat afMaterialDiffuseBackQuarter[4] = {0.0f, 0.16f, 0.31f, 0.25f};
 
1336
        static GLfloat afAxis[] = {0.0f, 1.0f, 0.0f};
 
1337
        static GLfloat afPosition[] = {0.0f, 0.0f, 0.0f};
 
1338
        static GLfloat fOldFactor = 0.0f;
645
1339
 
646
1340
        glClear (GL_COLOR_BUFFER_BIT);
647
1341
 
 
1342
        if (fOldFactor != fFactor)
 
1343
        {
 
1344
                int iPass;
 
1345
 
 
1346
                opengl_blur_pass (g_apTextures[1],
 
1347
                                  g_apTextures[4],
 
1348
                                  g_auiFragProgs[3],
 
1349
                                  fFactor,
 
1350
                                  HORIZONTAL_PASS,
 
1351
                                  iWidth,
 
1352
                                  iHeight);
 
1353
                opengl_blur_pass (g_apTextures[4],
 
1354
                                  g_apTextures[5],
 
1355
                                  g_auiFragProgs[3],
 
1356
                                  fFactor,
 
1357
                                  VERTICAL_PASS,
 
1358
                                  iWidth,
 
1359
                                  iHeight);
 
1360
                for (iPass = 0; iPass < 5; iPass++)
 
1361
                {
 
1362
                        opengl_blur_pass (g_apTextures[5],
 
1363
                                          g_apTextures[4],
 
1364
                                          g_auiFragProgs[3],
 
1365
                                          fFactor,
 
1366
                                          HORIZONTAL_PASS,
 
1367
                                          iWidth,
 
1368
                                          iHeight);
 
1369
                        opengl_blur_pass (g_apTextures[4],
 
1370
                                          g_apTextures[5],
 
1371
                                          g_auiFragProgs[3],
 
1372
                                          fFactor,
 
1373
                                          VERTICAL_PASS,
 
1374
                                          iWidth,
 
1375
                                          iHeight);
 
1376
                }
 
1377
 
 
1378
                fOldFactor = fFactor;
 
1379
        }
 
1380
 
648
1381
        /* disable texturing and lighting and draw the background using the
649
1382
        ** first shader */
650
1383
        opengl_change_projection (TRUE, iWidth, iHeight);
654
1387
        glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, g_auiFragProgs[0]);
655
1388
        opengl_paint_bg (-iWidth/2.0f, -iHeight/2.0f, iWidth, iHeight);
656
1389
 
657
 
        /* enable texturing and lighting and draw the spinning image with the
658
 
        ** other shader */
 
1390
        /* enable texturing and lighting and draw the spinning images with
 
1391
        ** other shaders */
659
1392
        opengl_change_projection (FALSE, iWidth, iHeight);
660
 
        glEnable (GL_TEXTURE_2D);
661
1393
        glEnable (GL_LIGHTING);
662
 
        glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, g_auiFragProgs[1]);
663
 
        fAngle += 1.0f;
664
 
 
665
 
        glBindTexture (GL_TEXTURE_2D, g_auiTextureIds[2]);
666
 
        glPushMatrix ();
667
 
        glTranslatef (-3.5f, 0.0f, -5.0f);
668
 
        glRotatef (fAngle, 0.0f, 1.0f, 0.0f);
669
 
        glBegin (GL_QUADS);
670
 
        /* left example  */
671
 
        glNormal3f (0.0f, 0.0f, 1.0f);
672
 
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
673
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontFull);
674
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackFull);
675
 
        glTexCoord2f (0.0f, 1.0f);
676
 
        glVertex3f (-1.5f, -1.5375f, 0.0f);
677
 
        glTexCoord2f (1.0f, 1.0f);
678
 
        glVertex3f ( 1.5f, -1.5375f, 0.0f);
679
 
        glTexCoord2f (1.0f, 0.0f);
680
 
        glVertex3f ( 1.5f,  1.4625f, 0.0f);
681
 
        glTexCoord2f (0.0f, 0.0f);
682
 
        glVertex3f (-1.5f,  1.4625f, 0.0f);
683
 
        /* left example's reflection */
684
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.0f);
685
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontOff);
686
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackOff);
687
 
        glTexCoord2f (0.0f, 0.5f);
688
 
        glVertex3f (-1.5f, -2.9625f, 0.0f);
689
 
        glTexCoord2f (1.0f, 0.5f);
690
 
        glVertex3f ( 1.5f, -2.9625f, 0.0f);
691
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.25f);
692
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontQuarter);
693
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackQuarter);
694
 
        glTexCoord2f (1.0f, 1.0f);
695
 
        glVertex3f ( 1.5f, -1.4625f, 0.0f);
696
 
        glTexCoord2f (0.0f, 1.0f);
697
 
        glVertex3f (-1.5f, -1.4625f, 0.0f);
698
 
        glEnd ();
699
 
        glPopMatrix ();
700
 
 
701
 
        glBindTexture (GL_TEXTURE_2D, g_auiTextureIds[1]);
702
 
        glPushMatrix ();
703
 
        glTranslatef (3.5f, 0.0f, -5.0f);
704
 
        glRotatef (fAngle, 0.0f, 1.0f, 0.0f);
705
 
        glBegin (GL_QUADS);
706
 
        /* right example */
707
 
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
708
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontFull);
709
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackFull);
710
 
        glTexCoord2f (0.0f, 1.0f);
711
 
        glVertex3f (-1.5f, -1.5f, 0.0f);
712
 
        glTexCoord2f (1.0f, 1.0f);
713
 
        glVertex3f ( 1.5f, -1.5f, 0.0f);
714
 
        glTexCoord2f (1.0f, 0.0f);
715
 
        glVertex3f ( 1.5f,  1.5f, 0.0f);
716
 
        glTexCoord2f (0.0f, 0.0f);
717
 
        glVertex3f (-1.5f,  1.5f, 0.0f);
718
 
        /* right example's reflection */
719
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.0f);
720
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontOff);
721
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackOff);
722
 
        glTexCoord2f (0.0f, 0.5f);
723
 
        glVertex3f (-1.5f, -3.0f, 0.0f);
724
 
        glTexCoord2f (1.0f, 0.5f);
725
 
        glVertex3f ( 1.5f, -3.0f, 0.0f);
726
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.25f);
727
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontQuarter);
728
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackQuarter);
729
 
        glTexCoord2f (1.0f, 1.0f);
730
 
        glVertex3f ( 1.5f, -1.5f, 0.0f);
731
 
        glTexCoord2f (0.0f, 1.0f);
732
 
        glVertex3f (-1.5f, -1.5f, 0.0f);
733
 
        glEnd ();
734
 
        glPopMatrix ();
735
 
 
736
 
        glBindTexture (GL_TEXTURE_2D, g_auiTextureIds[0]);
737
 
        glPushMatrix ();
738
 
        glTranslatef (0.0f, 0.0f, -5.0f);
739
 
        glRotatef (fAngle, 0.0f, 1.0f, 0.0f);
740
 
        glBegin (GL_QUADS);
741
 
        /* middle example */
742
 
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
743
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontFull);
744
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackFull);
745
 
        glTexCoord2f (0.0f, 1.0f);
746
 
        glVertex3f (-1.5f, -1.525f, 0.0f);
747
 
        glTexCoord2f (1.0f, 1.0f);
748
 
        glVertex3f ( 1.5f, -1.525f, 0.0f);
749
 
        glTexCoord2f (1.0f, 0.0f);
750
 
        glVertex3f ( 1.5f,  1.475f, 0.0f);
751
 
        glTexCoord2f (0.0f, 0.0f);
752
 
        glVertex3f (-1.5f,  1.475f, 0.0f);
753
 
        /* middle example's reflection */
754
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.0f);
755
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontOff);
756
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackOff);
757
 
        glTexCoord2f (0.0f, 0.5f);
758
 
        glVertex3f (-1.5f, -2.75f, 0.0f);
759
 
        glTexCoord2f (1.0f, 0.5f);
760
 
        glVertex3f ( 1.5f, -2.75f, 0.0f);
761
 
        glColor4f (1.0f, 1.0f, 1.0f, 0.25f);
762
 
        glMaterialfv (GL_FRONT, GL_DIFFUSE, afMaterialDiffuseFrontQuarter);
763
 
        glMaterialfv (GL_BACK, GL_DIFFUSE, afMaterialDiffuseBackQuarter);
764
 
        glTexCoord2f (1.0f, 1.0f);
765
 
        glVertex3f ( 1.5f, -1.475f, 0.0f);
766
 
        glTexCoord2f (0.0f, 1.0f);
767
 
        glVertex3f (-1.5f, -1.475f, 0.0f);
768
 
        glEnd ();
769
 
        glPopMatrix ();
 
1394
        fAngle += 1.5f;
 
1395
 
 
1396
        /* left thing */
 
1397
        afPosition[X] = -3.5f;
 
1398
        afPosition[Y] =  0.0f;
 
1399
        afPosition[Z] = -5.0f;
 
1400
        opengl_draw_textured_quad (g_apTextures[0],
 
1401
                                   g_auiFragProgs[4],
 
1402
                                   afPosition,
 
1403
                                   fAngle,
 
1404
                                   afAxis,
 
1405
                                   TRUE,
 
1406
                                   fFactor);
 
1407
        opengl_draw_textured_quad (g_apTextures[0],
 
1408
                                   g_auiFragProgs[4],
 
1409
                                   afPosition,
 
1410
                                   fAngle,
 
1411
                                   afAxis,
 
1412
                                   FALSE,
 
1413
                                   fFactor);
 
1414
 
 
1415
        /* middle thing */
 
1416
        afPosition[X] =  0.0f;
 
1417
        afPosition[Y] =  0.0f;
 
1418
        afPosition[Z] = -5.0f;
 
1419
        opengl_draw_textured_quad (g_apTextures[5],
 
1420
                                   g_auiFragProgs[1],
 
1421
                                   afPosition,
 
1422
                                   0.0f,
 
1423
                                   afAxis,
 
1424
                                   TRUE,
 
1425
                                   fFactor);
 
1426
        opengl_draw_textured_quad (g_apTextures[5],
 
1427
                                   g_auiFragProgs[1],
 
1428
                                   afPosition,
 
1429
                                   0.0f,
 
1430
                                   afAxis,
 
1431
                                   FALSE,
 
1432
                                   fFactor);
 
1433
 
 
1434
        /* right thing */
 
1435
        afPosition[X] =  3.5f;
 
1436
        afPosition[Y] =  0.0f;
 
1437
        afPosition[Z] = -5.0f;
 
1438
        opengl_draw_textured_quad (g_apTextures[2],
 
1439
                                   g_auiFragProgs[5],
 
1440
                                   afPosition,
 
1441
                                   fAngle,
 
1442
                                   afAxis,
 
1443
                                   TRUE,
 
1444
                                   fFactor);
 
1445
        opengl_draw_textured_quad (g_apTextures[2],
 
1446
                                   g_auiFragProgs[5],
 
1447
                                   afPosition,
 
1448
                                   fAngle,
 
1449
                                   afAxis,
 
1450
                                   FALSE,
 
1451
                                   fFactor);
770
1452
 
771
1453
        /* draw the text-labels */
772
1454
        opengl_change_projection (TRUE, iWidth, iHeight);
774
1456
        glDisable (GL_LIGHTING);
775
1457
        glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, g_auiFragProgs[2]);
776
1458
 
 
1459
        glActiveTexture (g_apTextTextures[0]->uiUnit);
777
1460
        glEnable (g_apTextTextures[0]->iTarget);
778
1461
        glBindTexture (g_apTextTextures[0]->iTarget,
779
1462
                       g_apTextTextures[0]->uiTextureId);
781
1464
        glTranslatef (- iWidth / 3 - g_apTextTextures[0]->fWidth / 2.0f, -1.0f * (GLfloat) iHeight / 2 + 20.0f, 0.0f);
782
1465
        glBegin (GL_QUADS);
783
1466
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
784
 
        glTexCoord2f (0.0f, g_apTextTextures[0]->fHeight);
 
1467
        glMultiTexCoord2fARB (g_apTextTextures[0]->uiUnit,
 
1468
                              0.0f,
 
1469
                              g_apTextTextures[0]->fHeight);
785
1470
        glVertex3f (0.0f, 0.0f, 0.0f);
786
 
        glTexCoord2f (g_apTextTextures[0]->fWidth,
787
 
                      g_apTextTextures[0]->fHeight);
 
1471
        glMultiTexCoord2fARB (g_apTextTextures[0]->uiUnit,
 
1472
                              g_apTextTextures[0]->fWidth,
 
1473
                              g_apTextTextures[0]->fHeight);
788
1474
        glVertex3f (g_apTextTextures[0]->fWidth, 0.0f, 0.0f);
789
 
        glTexCoord2f (g_apTextTextures[0]->fWidth, 0.0f);
 
1475
        glMultiTexCoord2fARB (g_apTextTextures[0]->uiUnit,
 
1476
                              g_apTextTextures[0]->fWidth,
 
1477
                              0.0f);
790
1478
        glVertex3f (g_apTextTextures[0]->fWidth,
791
1479
                    g_apTextTextures[0]->fHeight,
792
1480
                    0.0f);
793
 
        glTexCoord2f (0.0f, 0.0f);
 
1481
        glMultiTexCoord2fARB (g_apTextTextures[0]->uiUnit, 0.0f, 0.0f);
794
1482
        glVertex3f (0.0f, g_apTextTextures[0]->fHeight, 0.0f);
795
1483
        glEnd ();
796
1484
        glPopMatrix ();
797
1485
        glDisable (g_apTextTextures[0]->iTarget);
798
1486
 
 
1487
        glActiveTexture (g_apTextTextures[1]->uiUnit);
799
1488
        glEnable (g_apTextTextures[1]->iTarget);
800
1489
        glBindTexture (g_apTextTextures[1]->iTarget,
801
1490
                       g_apTextTextures[1]->uiTextureId);
803
1492
        glTranslatef (g_apTextTextures[1]->fWidth / -2.0f, -1.0f * (GLfloat) iHeight / 2 + 20.0f, 0.0f);
804
1493
        glBegin (GL_QUADS);
805
1494
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
806
 
        glTexCoord2f (0.0f, g_apTextTextures[1]->fHeight);
 
1495
        glMultiTexCoord2fARB (g_apTextTextures[1]->uiUnit,
 
1496
                              0.0f,
 
1497
                              g_apTextTextures[1]->fHeight);
807
1498
        glVertex3f (0.0f, 0.0f, 0.0f);
808
 
        glTexCoord2f (g_apTextTextures[1]->fWidth,
809
 
                      g_apTextTextures[1]->fHeight);
 
1499
        glMultiTexCoord2fARB (g_apTextTextures[1]->uiUnit,
 
1500
                              g_apTextTextures[1]->fWidth,
 
1501
                              g_apTextTextures[1]->fHeight);
810
1502
        glVertex3f (g_apTextTextures[1]->fWidth, 0.0f, 0.0f);
811
 
        glTexCoord2f (g_apTextTextures[1]->fWidth, 0.0f);
 
1503
        glMultiTexCoord2fARB (g_apTextTextures[1]->uiUnit,
 
1504
                              g_apTextTextures[1]->fWidth,
 
1505
                              0.0f);
812
1506
        glVertex3f (g_apTextTextures[1]->fWidth,
813
1507
                    g_apTextTextures[1]->fHeight,
814
1508
                    0.0f);
815
 
        glTexCoord2f (0.0f, 0.0f);
 
1509
        glMultiTexCoord2fARB (g_apTextTextures[1]->uiUnit,
 
1510
                              0.0f,
 
1511
                              0.0f);
816
1512
        glVertex3f (0.0f, g_apTextTextures[1]->fHeight, 0.0f);
817
1513
        glEnd ();
818
1514
        glPopMatrix ();
819
1515
        glDisable (g_apTextTextures[1]->iTarget);
820
1516
 
 
1517
        glActiveTexture (g_apTextTextures[2]->uiUnit);
821
1518
        glEnable (g_apTextTextures[2]->iTarget);
822
1519
        glBindTexture (g_apTextTextures[2]->iTarget,
823
1520
                       g_apTextTextures[2]->uiTextureId);
825
1522
        glTranslatef (iWidth / 3 - g_apTextTextures[2]->fWidth / 2.0f, -1.0f * (GLfloat) iHeight / 2 + 20.0f, 0.0f);
826
1523
        glBegin (GL_QUADS);
827
1524
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
828
 
        glTexCoord2f (0.0f, g_apTextTextures[2]->fHeight);
 
1525
        glMultiTexCoord2fARB (g_apTextTextures[2]->uiUnit,
 
1526
                              0.0f,
 
1527
                              g_apTextTextures[2]->fHeight);
829
1528
        glVertex3f (0.0f, 0.0f, 0.0f);
830
 
        glTexCoord2f (g_apTextTextures[2]->fWidth,
831
 
                      g_apTextTextures[2]->fHeight);
 
1529
        glMultiTexCoord2fARB (g_apTextTextures[2]->uiUnit,
 
1530
                              g_apTextTextures[2]->fWidth,
 
1531
                              g_apTextTextures[2]->fHeight);
832
1532
        glVertex3f (g_apTextTextures[2]->fWidth, 0.0f, 0.0f);
833
 
        glTexCoord2f (g_apTextTextures[2]->fWidth, 0.0f);
 
1533
        glMultiTexCoord2fARB (g_apTextTextures[2]->uiUnit,
 
1534
                              g_apTextTextures[2]->fWidth,
 
1535
                              0.0f);
834
1536
        glVertex3f (g_apTextTextures[2]->fWidth,
835
1537
                    g_apTextTextures[2]->fHeight,
836
1538
                    0.0f);
837
 
        glTexCoord2f (0.0f, 0.0f);
 
1539
        glMultiTexCoord2fARB (g_apTextTextures[2]->uiUnit, 0.0f, 0.0f);
838
1540
        glVertex3f (0.0f, g_apTextTextures[2]->fHeight, 0.0f);
839
1541
        glEnd ();
840
1542
        glPopMatrix ();
846
1548
opengl_cleanup (void)
847
1549
{
848
1550
        if (g_bHasShaders)
849
 
                glDeleteProgramsARB (3, g_auiFragProgs);
850
 
 
851
 
        glDeleteTextures (3, g_auiTextureIds);
852
 
 
853
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[0]);
854
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[1]);
855
 
        g_slice_free1 (sizeof (Texture), (gpointer) g_apTextTextures[2]);
 
1551
                glDeleteProgramsARB (5, g_auiFragProgs);
 
1552
 
 
1553
        opengl_delete_texture (g_apTextures[0]);
 
1554
        opengl_delete_texture (g_apTextures[1]);
 
1555
        opengl_delete_texture (g_apTextures[2]);
 
1556
        opengl_delete_texture (g_apTextures[3]);
 
1557
        opengl_delete_texture (g_apTextures[4]);
 
1558
        opengl_delete_texture (g_apTextures[5]);
 
1559
 
 
1560
        opengl_delete_texture (g_apTextTextures[0]);
 
1561
        opengl_delete_texture (g_apTextTextures[1]);
 
1562
        opengl_delete_texture (g_apTextTextures[2]);
856
1563
}