Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using OpenTK;
- using System;
- using OpenTK.Graphics;
- using Labs.Utility;
- using OpenTK.Graphics.OpenGL;
- namespace Labs.ACW
- {
- class cube
- {
- public enum cubeType
- {
- Bottom,
- Middle,
- Top
- };
- Matrix4 Position;
- cubeType cubeStructure;
- public cube(string inCubeStructure, Matrix4 inPosition)
- {
- switch (inCubeStructure)
- {
- case "Top":
- cubeStructure = cubeType.Top;
- break;
- case "Middle":
- cubeStructure = cubeType.Middle;
- break;
- case "Bottom":
- cubeStructure = cubeType.Bottom;
- break;
- }
- Position = inPosition;
- }
- public void OnLoad(EventArgs e)
- {
- float[] cubeVertices = new float[] {
- // Top
- 0, 1, 0, 0, 1, 0,
- 1, 1, 0, 0, 1, 0,
- 1, 1, 1, 0, 1, 0,
- 0, 1, 0, 0, 1, 0,
- 1, 1, 1, 0, 1, 0,
- 0, 1, 1, 0, 1, 0,
- // Side 1 - Front Side
- 0, 1, 1, 0, 1, 0,
- 1, 1, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0,
- 0, 1, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0,
- 0, 0, 1, 0, 1, 0,
- // Side 2 - Left Side
- 0, 1, 0, 0, 1, 0,
- 0, 0, 1, 0, 1, 0,
- 0, 0, 0, 0, 1, 0,
- 0, 1, 0, 0, 1, 0,
- 0, 1, 1, 0, 1, 0,
- 0, 0, 1, 0, 1, 0,
- // Side 3 - Back Side
- 1, 1, 0, 0, 1, 0,
- 0, 0, 0, 0, 1, 0,
- 1, 0, 0, 0, 1, 0,
- 1, 1, 0, 0, 1, 0,
- 0, 1, 0, 0, 1, 0,
- 0, 0, 0, 0, 1, 0,
- // Side 4 - Right Side
- 1, 1, 1, 0, 1, 0,
- 1, 0, 0, 0, 1, 0,
- 1, 0, 1, 0, 1, 0,
- 1, 1, 1, 0, 1, 0,
- 1, 1, 0, 0, 1, 0,
- 1, 0, 0, 0, 1, 0,
- // Bottom
- 0, 0, 0, 0, 1, 0,
- 0, 0, 1, 0, 1, 0,
- 1, 0, 1, 0, 1, 0,
- 0, 0, 0, 0, 1, 0,
- 1, 0, 1, 0, 1, 0,
- 1, 0, 0, 0, 1, 0
- };
- // Bind Vertex Array
- GL.BindVertexArray(ACWWindow.mVertexArrayObjectIDArray[0]);
- // Bind Vertex Buffer
- GL.BindBuffer(BufferTarget.ArrayBuffer, ACWWindow.mVertexBufferObjectIDArray[0]);
- GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(cubeVertices.Length * sizeof(float)), cubeVertices, BufferUsageHint.StaticDraw);
- // Ensure Cube is loaded correctly
- int size;
- GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
- if (cubeVertices.Length * sizeof(float) != size)
- {
- throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
- }
- int vPositionLocation = GL.GetAttribLocation(ACWWindow.mShader.ShaderProgramID, "vPosition");
- int vNormalLocation = GL.GetAttribLocation(ACWWindow.mShader.ShaderProgramID, "vNormal");
- // Position and Normal
- GL.EnableVertexAttribArray(vPositionLocation);
- GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
- GL.EnableVertexAttribArray(vNormalLocation);
- GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
- }
- public void OnRenderFrame(FrameEventArgs e)
- {
- // Draw Cube
- int uModel = GL.GetUniformLocation(ACWWindow.mShader.ShaderProgramID, "uModel");
- GL.UniformMatrix4(uModel, true, ref Position);
- GL.BindVertexArray(ACWWindow.mVertexArrayObjectIDArray[0]);
- switch (cubeStructure)
- {
- case cubeType.Top:
- GL.DrawArrays(PrimitiveType.Triangles, 0, 30);
- break;
- case cubeType.Middle:
- GL.DrawArrays(PrimitiveType.Triangles, 6, 30);
- break;
- case cubeType.Bottom:
- GL.DrawArrays(PrimitiveType.Triangles, 6, 36);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement