Commits

Cliff Biffle  committed 5eb9cfd

Added a quad renderer based on the mesh renderer.

  • Participants
  • Parent commits 80969a7

Comments (0)

Files changed (1)

File KVDepthView.m

 - (void) drawDepthFieldAsPoints;
 - (void) drawDepthFieldAsCards;
 - (void) drawDepthFieldAsMesh;
+- (void) drawDepthFieldAsQuads;
 @end
 
 @implementation KVDepthView
   glEnd();
 }
 
+- (void) drawDepthFieldAsQuads {
+  axes();
+  
+  const GLfloat *depths = [linearDepthField bytes];
+  
+  glBegin(GL_QUADS);
+  for (int y = 0; y < 479; y++) {
+    for (int x = 0; x < 639; x++) {
+      int xs[4] = { x, x, x + 1, x + 1 };
+      int ys[4] = { y, y + 1, y + 1, y };
+      
+      BOOL skip = NO;
+      vec3f_t coords[4];
+      GLfloat colors[4];
+      for (int i = 0; i < 4; i++) {
+        GLfloat d = depths[ys[i] * 640 + xs[i]];
+        if (d < 0.1F) skip = YES;
+        
+        GLfloat dr = 1.F + d;
+        coords[i].x = (xs[i] - 320.F) * dr + 320.F;
+        coords[i].y = (ys[i] - 240.F) * dr + 240.F;
+        coords[i].z = d;
+        colors[i] = 1.F - (d / 6.F);
+      }
+      
+      if (skip) continue;
+      
+      for (int i = 0; i < 4; i++) {
+        glColor3f(colors[i], colors[i], colors[i]);
+        glVertex3fv((GLfloat *) &coords[i]);
+      }
+    }
+  }
+  glEnd();
+}
+
 - (void) drawDepthFieldAsMesh {
   axes();