|
@@ -18,7 +18,14 @@ namespace bbiwarg.Graphics
|
|
|
private Point[,] depthPixels = new Point[320,240];
|
|
|
private List<IGraphicElement> graphicElements = new List<IGraphicElement>();
|
|
|
private Point palmPixel;
|
|
|
- private Point[] fingerPixel = new Point[5];
|
|
|
+ private Point[] fingerPixel = new Point[5];
|
|
|
+ private int VBOid = new int();
|
|
|
+ private int IBOid = new int();
|
|
|
+ private float[] vertices = new float[0];
|
|
|
+ private uint[] triangles = new uint[0];
|
|
|
+ private int width = 320;
|
|
|
+ private int height = 240;
|
|
|
+
|
|
|
|
|
|
public Output(IVideoDataSource source)
|
|
|
{
|
|
@@ -57,8 +64,11 @@ namespace bbiwarg.Graphics
|
|
|
|
|
|
fingerPixel[i] = new Point(vertex, palmColor, palmSize);
|
|
|
graphicElements.Add(fingerPixel[i]);
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ initBuffers();
|
|
|
+ updateData(graphicElements);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
|
@@ -72,8 +82,8 @@ namespace bbiwarg.Graphics
|
|
|
source.updateFrame();
|
|
|
|
|
|
ImageData image = source.getImageData();
|
|
|
- int width = image.getWidth();
|
|
|
- int height = image.getHeight();
|
|
|
+ width = image.getWidth();
|
|
|
+ height = image.getHeight();
|
|
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
for (int y = 0; y < height; y++) {
|
|
@@ -106,11 +116,15 @@ namespace bbiwarg.Graphics
|
|
|
fingerPixel[i].position.z = 0;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /*
|
|
|
foreach (IGraphicElement graphicElement in graphicElements)
|
|
|
{
|
|
|
graphicElement.draw(width, height);
|
|
|
}
|
|
|
+ */
|
|
|
+
|
|
|
+ updateData(graphicElements);
|
|
|
+ drawBuffer();
|
|
|
|
|
|
SwapBuffers();
|
|
|
source.releaseFrame();
|
|
@@ -124,6 +138,81 @@ namespace bbiwarg.Graphics
|
|
|
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 3000.0f);
|
|
|
GL.MatrixMode(MatrixMode.Projection);
|
|
|
GL.LoadMatrix(ref projection);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initBuffers()
|
|
|
+ {
|
|
|
+ GL.EnableClientState(ArrayCap.VertexArray);
|
|
|
+
|
|
|
+ GL.GenBuffers(1, out VBOid);
|
|
|
+ GL.GenBuffers(1, out IBOid);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
|
|
|
+ GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StreamDraw);
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
+
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
|
|
|
+ GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(triangles.Length * sizeof(int)), triangles, BufferUsageHint.StaticDraw);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawBuffer()
|
|
|
+ {
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
|
|
|
+
|
|
|
+ GL.InterleavedArrays(InterleavedArrayFormat.C3fV3f, 0, IntPtr.Zero);
|
|
|
+ GL.DrawElements(BeginMode.Triangles, triangles.Length, DrawElementsType.UnsignedInt, 0);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateData(List<IGraphicElement> list)
|
|
|
+ {
|
|
|
+ List<float> verticesData = new List<float>();
|
|
|
+ List<uint> triangleData = new List<uint>();
|
|
|
+
|
|
|
+ foreach (IGraphicElement graphicElement in list)
|
|
|
+ {
|
|
|
+ List<Vector> elementVertices = graphicElement.getVertices(width, height);
|
|
|
+ uint[] elementTriangles = graphicElement.getTriangleIndices();
|
|
|
+ Color elementColor = graphicElement.getColor();
|
|
|
+
|
|
|
+ uint c = (uint)verticesData.Count / 6;
|
|
|
+ foreach (Vector elementVertex in elementVertices)
|
|
|
+ {
|
|
|
+ verticesData.AddRange(convertColor(elementColor));
|
|
|
+ verticesData.AddRange(elementVertex);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < elementTriangles.Length; i++)
|
|
|
+ {
|
|
|
+ triangleData.Add(elementTriangles[i] + c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vertices = verticesData.ToArray();
|
|
|
+ triangles = triangleData.ToArray();
|
|
|
+
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, VBOid);
|
|
|
+ GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * sizeof(float)), vertices, BufferUsageHint.StreamDraw);
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, IBOid);
|
|
|
+ GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(triangles.Length * sizeof(int)), triangles, BufferUsageHint.StaticDraw);
|
|
|
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<float> convertColor(Color color)
|
|
|
+ {
|
|
|
+ List<float> result = new List<float>();
|
|
|
+ result.Add(color.R / 255f);
|
|
|
+ result.Add(color.G / 255f);
|
|
|
+ result.Add(color.B / 255f);
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
}
|