fixed more animation bugs, added rudimentary UI
[faros-demo] / src / geom.cc
index 62e36d3..770b438 100644 (file)
@@ -1,20 +1,52 @@
+#include <math.h>
 #include <GL/glew.h>
 #include <GL/freeglut.h>
 #include "geom.h"
 #include "sdr.h"
 
 static unsigned int sdr_curve_top;
+static unsigned int tex_xcircle;
+
+static const unsigned char tex_xcircle_pixels[] = {
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 64, 255, 255, 255, 255, 64, 0,
+
+       0, 64, 255, 255, 255, 255, 64, 0,
+       0, 0, 255, 255, 255, 255, 0, 0,
+       0, 0, 128, 255, 255, 128, 0, 0,
+       0, 0, 0, 64, 64, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0
+};
+
 
 bool init_geom()
 {
        if(!(sdr_curve_top = create_program_load("sdr/curve_top.v.glsl", "sdr/curve_top.f.glsl"))) {
                return false;
        }
+
+       glGenTextures(1, &tex_xcircle);
+       glBindTexture(GL_TEXTURE_2D, tex_xcircle);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 16, 0,
+                       GL_LUMINANCE, GL_UNSIGNED_BYTE, tex_xcircle_pixels);
        return true;
 }
 
 void destroy_geom()
 {
+       glDeleteTextures(1, &tex_xcircle);
        free_program(sdr_curve_top);
 }
 
@@ -112,7 +144,7 @@ void ground()
        glPopMatrix();
 }
 
-void xlogo()
+void xlogo(float sz, float alpha, float xcircle)
 {
        static const float xlogo_varr[] = {
                -0.500, 0.407, -0.113, -0.109, 0.059, -0.006, -0.251, 0.407,
@@ -124,23 +156,57 @@ void xlogo()
        /* billboarding */
        float mv[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, mv);
-       mv[0] = mv[5] = mv[10] = 1.0f;
+       mv[0] = mv[5] = mv[10] = sz;
        mv[1] = mv[2] = mv[4] = mv[6] = mv[8] = mv[9] = 0.0f;
 
        glPushMatrix();
        glLoadMatrixf(mv);
+       glTranslatef(0, 0.15, 0);
 
        glPushAttrib(GL_ENABLE_BIT);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
        glBegin(GL_QUADS);
+       glColor4f(0, 0, 0, alpha);
        const float *vptr = xlogo_varr;
        for(int i=0; i<(int)(sizeof xlogo_varr / sizeof *xlogo_varr) / 2; i++) {
                glVertex2fv(vptr);
                vptr += 2;
        }
        glEnd();
+       glTranslatef(0, -0.15, 0);
+       glDisable(GL_BLEND);
+
+       glEnable(GL_TEXTURE_2D);
+       glBindTexture(GL_TEXTURE_2D, tex_xcircle);
+
+       glDisable(GL_CULL_FACE);
+       glEnable(GL_ALPHA_TEST);
+       float aref = 1.0f - xcircle;
+       glAlphaFunc(GL_GREATER, aref > 0.0f ? aref : 0.0f);
+
+       glScalef(1.4, 1, 1);
+
+#define XLOGO_CIRCLE_SEG       64
+       // circle thingy
+       glBegin(GL_QUAD_STRIP);
+       for(int i=0; i<XLOGO_CIRCLE_SEG; i++) {
+               float t = (float)i / (float)(XLOGO_CIRCLE_SEG - 1);
+               float tcol = fmod(t + 0.075f, 1.0f);
+
+               float theta = t * M_PI * 2.0f;
+               float rad = 0.4f;
+               float width = 0.05f * tcol;
+               float z = -cos(theta) * 0.1;
+
+               glColor4f(0.9, 0.9, 0.9, tcol);
+               glTexCoord2f(0, 1.0f - tcol);
+               glVertex3f(sin(theta) * (rad + width), cos(theta) * (rad + width), z);
+               glTexCoord2f(1, 1.0f - tcol);
+               glVertex3f(sin(theta) * (rad - width), cos(theta) * (rad - width), z);
+       }
+       glEnd();
 
        glPopAttrib();
        glPopMatrix();