static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); // multisampling makes things beautiful! Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); Gl.Enable(EnableCap.DepthTest); Gl.Enable(EnableCap.Multisample); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up)); program["light_direction"].SetValue(new Vector3(0, 0, 1)); program["enable_lighting"].SetValue(lighting); program["normalTexture"].SetValue(1); program["enable_mapping"].SetValue(normalMapping); brickDiffuse = new Texture("AlternatingBrick-ColorMap.png"); brickNormals = new Texture("AlternatingBrick-NormalMap.png"); Vector3[] vertices = new Vector3[] { new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1), // top new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1), // bottom new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1), // front face new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1), // back face new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1), // left new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) }; cube = new VBO<Vector3>(vertices); Vector2[] uvs = new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) }; cubeUV = new VBO<Vector2>(uvs); List<int> triangles = new List<int>(); for (int i = 0; i < 6; i++) { triangles.Add(i * 4); triangles.Add(i * 4 + 1); triangles.Add(i * 4 + 2); triangles.Add(i * 4); triangles.Add(i * 4 + 2); triangles.Add(i * 4 + 3); } cubeTriangles = new VBO<int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer); Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray()); cubeNormals = new VBO<Vector3>(normals); Vector3[] tangents = CalculateTangents(vertices, normals, triangles.ToArray(), uvs); cubeTangents = new VBO<Vector3>(tangents); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 13"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE); // multisampling makes things beautiful! Glut.glutInitWindowSize(width, height); Glut.glutCreateWindow("OpenGL Tutorial"); Glut.glutIdleFunc(OnRenderFrame); Glut.glutDisplayFunc(OnDisplay); Glut.glutKeyboardFunc(OnKeyboardDown); Glut.glutKeyboardUpFunc(OnKeyboardUp); Glut.glutCloseFunc(OnClose); Glut.glutReshapeFunc(OnReshape); // enable blending and set to accumulate the star colors Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.ProgramPointSize); Gl.Enable(EnableCap.Multisample); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); // create our shader program program = new ShaderProgram(VertexShader, FragmentShader); // set up the projection and view matrix program.Use(); program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, Vector3.Up)); program["model_matrix"].SetValue(Matrix4.Identity); program["static_colors"].SetValue(false); // load the particle texture particleTexture = new Texture("star.bmp"); // set up the particlePoints VBO, which will stay constant int[] points = new int[particleCount]; for (int i = 0; i < points.Length; i++) points[i] = i; particlePoints = new VBO<int>(points, BufferTarget.ElementArrayBuffer); // set up the particleColors, which we'll just keep static Vector3[] colors = new Vector3[particleCount]; for (int i = 0; i < colors.Length; i++) colors[i] = new Vector3(generator.NextDouble(), generator.NextDouble(), generator.NextDouble()); particleColors = new VBO<Vector3>(colors); // build up our first batch of 1000 particles and 1000 static colors for (int i = 0; i < particleCount; i++) particles.Add(new Particle(Vector3.Zero, 0)); // load the bitmap font for this tutorial font = new BMFont("font24.fnt", "font24.png"); fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource); fontProgram.Use(); fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000)); fontProgram["color"].SetValue(new Vector3(1, 1, 1)); information = font.CreateString(fontProgram, "OpenGL C# Tutorial 12"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }