conworlds

annotate src/vr/vr_null.c @ 10:e3f0ca1d008a

added preliminary OpenHMD module
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 20:11:15 +0300
parents bd8202d6d28d
children
rev   line source
nuclear@4 1 #ifdef WIN32
nuclear@4 2 #define WIN32_LEAN_AND_MEAN
nuclear@4 3 #include <windows.h>
nuclear@4 4 #endif
nuclear@4 5 #ifdef __APPLE__
nuclear@4 6 #include <OpenGL/gl.h>
nuclear@4 7 #else
nuclear@4 8 #include <GL/gl.h>
nuclear@4 9 #endif
nuclear@4 10 #include "vr_impl.h"
nuclear@4 11
nuclear@7 12 static unsigned int eye_tex[2];
nuclear@7 13 static float tex_umin[2], tex_umax[2];
nuclear@7 14 static float tex_vmin[2], tex_vmax[2];
nuclear@7 15
nuclear@4 16 static int init(void)
nuclear@4 17 {
nuclear@4 18 return 0;
nuclear@4 19 }
nuclear@4 20
nuclear@8 21 static int present(void)
nuclear@7 22 {
nuclear@7 23 int i;
nuclear@7 24
nuclear@7 25 glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
nuclear@7 26
nuclear@7 27 glDisable(GL_LIGHTING);
nuclear@7 28 glDisable(GL_DEPTH_TEST);
nuclear@7 29 glDisable(GL_FOG);
nuclear@7 30 glDisable(GL_CULL_FACE);
nuclear@7 31
nuclear@7 32 glEnable(GL_TEXTURE_2D);
nuclear@7 33
nuclear@7 34 glMatrixMode(GL_MODELVIEW);
nuclear@7 35 glLoadIdentity();
nuclear@7 36 glMatrixMode(GL_PROJECTION);
nuclear@7 37 glLoadIdentity();
nuclear@7 38
nuclear@7 39 for(i=0; i<2; i++) {
nuclear@7 40 float x0 = i == 0 ? -1 : 0;
nuclear@7 41 float x1 = i == 0 ? 0 : 1;
nuclear@7 42
nuclear@7 43 glBindTexture(GL_TEXTURE_2D, eye_tex[i]);
nuclear@7 44
nuclear@7 45 glBegin(GL_QUADS);
nuclear@7 46 glTexCoord2f(tex_umin[i], tex_vmin[i]);
nuclear@7 47 glVertex2f(x0, -1);
nuclear@7 48 glTexCoord2f(tex_umax[i], tex_vmin[i]);
nuclear@7 49 glVertex2f(x1, -1);
nuclear@7 50 glTexCoord2f(tex_umax[i], tex_vmax[i]);
nuclear@7 51 glVertex2f(x1, 1);
nuclear@7 52 glTexCoord2f(tex_umin[i], tex_vmax[i]);
nuclear@7 53 glVertex2f(x0, 1);
nuclear@7 54 glEnd();
nuclear@7 55 }
nuclear@7 56
nuclear@7 57 glPopMatrix();
nuclear@7 58 glMatrixMode(GL_MODELVIEW);
nuclear@7 59 glPopMatrix();
nuclear@7 60
nuclear@7 61 glPopAttrib();
nuclear@8 62 return 0;
nuclear@7 63 }
nuclear@7 64
nuclear@7 65 static void set_eye_texture(int eye, unsigned int tex, float umin, float vmin, float umax, float vmax)
nuclear@7 66 {
nuclear@7 67 eye_tex[eye] = tex;
nuclear@7 68 tex_umin[eye] = umin;
nuclear@7 69 tex_umax[eye] = umax;
nuclear@7 70 tex_vmin[eye] = vmin;
nuclear@7 71 tex_vmax[eye] = vmax;
nuclear@7 72 }
nuclear@7 73
nuclear@4 74 struct vr_module *vr_module_null(void)
nuclear@4 75 {
nuclear@4 76 static struct vr_module m;
nuclear@4 77
nuclear@4 78 if(!m.init) {
nuclear@4 79 m.name = "null";
nuclear@4 80 m.init = init;
nuclear@7 81 m.set_eye_texture = set_eye_texture;
nuclear@7 82 m.present = present;
nuclear@4 83 }
nuclear@4 84 return &m;
nuclear@4 85 }