private unsafe void InitVertexBuffers() { { VR04PositionBuffer positionBuffer = new VR04PositionBuffer(strin_Position); positionBuffer.Alloc(zFrameCount); QuadPosition* array = (QuadPosition*)positionBuffer.FirstElement(); for (int i = 0; i < zFrameCount; i++) { array[i] = new QuadPosition( new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f) ); } this.positionBufferRenderer = positionBuffer.GetRenderer(); positionBuffer.Dispose(); } { VR04UVBuffer uvBuffer = new VR04UVBuffer(strin_uv); uvBuffer.Alloc(zFrameCount); QuadUV* array = (QuadUV*)uvBuffer.FirstElement(); for (int i = 0; i < zFrameCount; i++) { array[i] = new QuadUV( new vec3(0, 0, (float)i / (float)zFrameCount), new vec3(1, 0, (float)i / (float)zFrameCount), new vec3(1, 1, (float)i / (float)zFrameCount), new vec3(0, 1, (float)i / (float)zFrameCount) ); } this.uvBufferRenderer = uvBuffer.GetRenderer(); uvBuffer.Dispose(); } { var indexBuffer = new VR04IndexBuffer(); indexBuffer.Alloc(zFrameCount); QuadIndex* array = (QuadIndex*)indexBuffer.FirstElement(); for (uint i = 0; i < zFrameCount; i++) { if (this.reverSide) array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0, (zFrameCount - i - 1) * 4 + 1, (zFrameCount - i - 1) * 4 + 2, (zFrameCount - i - 1) * 4 + 3 ); else { array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3); } } this.indexBufferRenderer = indexBuffer.GetRenderer(); indexBuffer.Dispose(); } //if (!this.reverSide) //{ // var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, zFrameCount * 4); // indexBuffer.Alloc(zFrameCount);// this actually does nothing. // this.indexBufferRenderer = indexBuffer.GetRenderer(); // indexBuffer.Dispose(); //} //else //{ // var indexBuffer = new VR04IndexBuffer(); // indexBuffer.Alloc(zFrameCount); // QuadIndex* array = (QuadIndex*)indexBuffer.FirstElement(); // for (uint i = 0; i < zFrameCount; i++) // { // //array[i] = new QuadIndex(i * 4 + 0, i * 4 + 1, i * 4 + 2, i * 4 + 3); // array[i] = new QuadIndex((zFrameCount - i - 1) * 4 + 0, // (zFrameCount - i - 1) * 4 + 1, // (zFrameCount - i - 1) * 4 + 2, // (zFrameCount - i - 1) * 4 + 3 // ); // } // this.indexBufferRenderer = indexBuffer.GetRenderer(); // indexBuffer.Dispose(); //} this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer); }
private unsafe void InitVertexBuffers() { { VR02PositionBuffer positionBuffer = new VR02PositionBuffer(strin_Position); positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount); vec3* array = (vec3*)positionBuffer.FirstElement(); int index = 0; for (int i = 0; i < xFrameCount; i++) { for (int j = 0; j < yFrameCount; j++) { for (int k = 0; k < zFrameCount; k++) { array[index++] = new vec3( (float)i / (float)xFrameCount - 0.5f, (float)j / (float)yFrameCount - 0.5f, ((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f ); } } } this.positionBufferRenderer = positionBuffer.GetRenderer(); positionBuffer.Dispose(); } { VR02UVBuffer uvBuffer = new VR02UVBuffer(strin_uv); uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount); vec3* array = (vec3*)uvBuffer.FirstElement(); int index = 0; for (int i = 0; i < xFrameCount; i++) { for (int j = 0; j < yFrameCount; j++) { for (int k = 0; k < zFrameCount; k++) { array[index++] = new vec3( (float)i / (float)xFrameCount, (float)j / (float)yFrameCount, (float)k / (float)zFrameCount ); } } } this.uvBufferRenderer = uvBuffer.GetRenderer(); uvBuffer.Dispose(); } { var indexBuffer = new ZeroIndexBuffer(DrawMode.Points, 0, xFrameCount * yFrameCount * zFrameCount); indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount);// this actually does nothing. this.indexBufferRenderer = indexBuffer.GetRenderer() as ZeroIndexBufferRenderer; indexBuffer.Dispose(); } this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer); }
private unsafe void InitVertexBuffers() { { VR01PositionBuffer positionBuffer = new VR01PositionBuffer(strin_Position); positionBuffer.Alloc(zFrameCount); QuadPosition* array = (QuadPosition*)positionBuffer.FirstElement(); for (int i = 0; i < zFrameCount; i++) { array[i] = new QuadPosition( new vec3(-xLength, -yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(xLength, -yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(xLength, yLength, (float)i / (float)zFrameCount - 0.5f), new vec3(-xLength, yLength, (float)i / (float)zFrameCount - 0.5f) ); } this.positionBufferRenderer = positionBuffer.GetRenderer(); positionBuffer.Dispose(); } { VR01UVBuffer uvBuffer = new VR01UVBuffer(strin_uv); uvBuffer.Alloc(zFrameCount); QuadUV* array = (QuadUV*)uvBuffer.FirstElement(); for (int i = 0; i < zFrameCount; i++) { array[i] = new QuadUV( new vec3(0, 0, (float)i / (float)zFrameCount), new vec3(1, 0, (float)i / (float)zFrameCount), new vec3(1, 1, (float)i / (float)zFrameCount), new vec3(0, 1, (float)i / (float)zFrameCount) ); } this.uvBufferRenderer = uvBuffer.GetRenderer(); uvBuffer.Dispose(); } { var indexBuffer = new ZeroIndexBuffer(DrawMode.Quads, 0, zFrameCount * 4); indexBuffer.Alloc(zFrameCount);// this actually does nothing. this.indexBufferRenderer = indexBuffer.GetRenderer(); indexBuffer.Dispose(); } this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer); }
protected override void DoRender(RenderEventArgs e) { if (this.axisVAO == null) { this.axisVAO = new VertexArrayObject[3]; for (int i = 0; i < 3; i++) { var vao = new VertexArrayObject(this.positionBufferRenderers[i], this.colorBufferRenderers[i], this.indexBufferRenderers[i]); vao.Create(e, this.shaderProgram); this.axisVAO[i] = vao; } { var vao = new VertexArrayObject(this.planPositionBufferRenderer, planColorBufferRenderer, this.planIndexBufferRenderer); vao.Create(e, this.shaderProgram); this.planVAO = vao; } } // 绑定shader this.shaderProgram.Bind(); // 画坐标轴 for (int i = 0; i < 3; i++) { this.axisVAO[i].Render(e, this.shaderProgram); } // 画平面 { this.planVAO.Render(e, this.shaderProgram); } // 解绑shader this.shaderProgram.Unbind(); }
protected override void DoRender(RenderEventArgs e) { ShaderProgram program = this.shaderProgram; // 绑定shader program.Bind(); program.SetUniformMatrix4(strprojectionMatrix, projectionMatrix.to_array()); program.SetUniformMatrix4(strviewMatrix, viewMatrix.to_array()); program.SetUniformMatrix4(strmodelMatrix, modelMatrix.to_array()); int[] originalPolygonMode = new int[1]; GL.GetInteger(GetTarget.PolygonMode, originalPolygonMode); GL.PolygonMode(PolygonModeFaces.FrontAndBack, this.polygonMode); if (this.vertexArrayObject == null) { var vao = new VertexArrayObject( this.positionBufferRenderer, //this.colorBufferRenderer, this.normalBufferRenderer, this.indexBufferRenderer); vao.Create(e, this.shaderProgram); this.vertexArrayObject = vao; } else { this.vertexArrayObject.Render(e, this.shaderProgram); } GL.PolygonMode(PolygonModeFaces.FrontAndBack, (PolygonModes)(originalPolygonMode[0])); // 解绑shader program.Unbind(); }
private unsafe void InitVertexBuffers() { // http://images.cnblogs.com/cnblogs_com/bitzhuwei/482613/o_Cube-small.jpg { VR03PositionBuffer positionBuffer = new VR03PositionBuffer(strin_Position); positionBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount); HexahedronPosition* array = (HexahedronPosition*)positionBuffer.FirstElement(); int index = 0; for (int i = 0; i < xFrameCount; i++) { for (int j = 0; j < yFrameCount; j++) { for (int k = 0; k < zFrameCount; k++) { var x = ((float)i / (float)xFrameCount - 0.5f) * factor; var y = ((float)j / (float)yFrameCount - 0.5f) * factor; var z = (((float)k / (float)zFrameCount - 0.5f) * 109.0f / 256.0f) * factor; var hexahedron = new HexahedronPosition(); hexahedron.v0 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength); hexahedron.v1 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z + hexahedronHalfLength); hexahedron.v2 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength); hexahedron.v3 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z + hexahedronHalfLength); hexahedron.v4 = new vec3(x + hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength); hexahedron.v5 = new vec3(x - hexahedronHalfLength, y + hexahedronHalfLength, z - hexahedronHalfLength); hexahedron.v6 = new vec3(x + hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength); hexahedron.v7 = new vec3(x - hexahedronHalfLength, y - hexahedronHalfLength, z - hexahedronHalfLength); array[index++] = hexahedron; } } } this.positionBufferRenderer = positionBuffer.GetRenderer(); positionBuffer.Dispose(); } { VR03UVBuffer uvBuffer = new VR03UVBuffer(strin_uv); uvBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount); HexahedronUV* array = (HexahedronUV*)uvBuffer.FirstElement(); int index = 0; for (int i = 0; i < xFrameCount; i++) { for (int j = 0; j < yFrameCount; j++) { for (int k = 0; k < zFrameCount; k++) { var x = (float)i / (float)xFrameCount; var y = (float)j / (float)yFrameCount; var z = (float)k / (float)zFrameCount; var color = new vec3(x, y, z); var uv = new HexahedronUV(); uv.v0 = color; uv.v1 = color; uv.v2 = color; uv.v3 = color; uv.v4 = color; uv.v5 = color; uv.v6 = color; uv.v7 = color; array[index++] = uv; } } } this.uvBufferRenderer = uvBuffer.GetRenderer(); uvBuffer.Dispose(); } { var indexBuffer = new VR03IndexBuffer(); indexBuffer.Alloc(xFrameCount * yFrameCount * zFrameCount); HexahedronIndex* array = (HexahedronIndex*)indexBuffer.FirstElement(); int index = 0; for (int i = 0; i < xFrameCount; i++) { for (int j = 0; j < yFrameCount; j++) { for (int k = 0; k < zFrameCount; k++) { uint centerIndex = (uint)((i * yFrameCount * zFrameCount + j * zFrameCount + k) * 8); array[index++] = new HexahedronIndex(centerIndex); } } } this.indexBufferRenderer = indexBuffer.GetRenderer(); indexBuffer.Dispose(); } this.vao = new VertexArrayObject(this.positionBufferRenderer, this.uvBufferRenderer, this.indexBufferRenderer); }