static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); 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.DepthTest); Gl.Enable(EnableCap.Blend); // 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, new Vector3(0, 1, 0))); program["model_matrix"].SetValue(Matrix4.Identity); // load the flag texture flagTexture = new Texture("flag.png"); // create the flag, which is just a plane with a certain number of segments List <Vector3> vertices = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <uint> triangles = new List <uint>(); for (int x = 0; x < 40; x++) { for (int y = 0; y < 40; y++) { vertices.Add(new Vector3((x - 20) / 5.0f, (y - 20) / 10.0f, 0)); uvs.Add(new Vector2(x / 39.0f, 1 - y / 39.0f)); if (y == 39 || x == 39) { continue; } triangles.Add((uint)(x * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y + 1)); triangles.Add((uint)(x * 40 + y)); triangles.Add((uint)((x + 1) * 40 + y + 1)); triangles.Add((uint)(x * 40 + y + 1)); } } flagVertices = new VBO <Vector3>(vertices.ToArray()); flagUVs = new VBO <Vector2>(uvs.ToArray()); flagTriangles = new VBO <uint>(triangles.ToArray(), BufferTarget.ElementArrayBuffer); // 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 11"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }
static void Main(string[] args) { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH); 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.DepthTest); Gl.Enable(EnableCap.Blend); // 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); // load the flag texture flagTexture = new Texture("flag.png"); // create the flag, which is just a plane with a certain number of segments List<Vector3> vertices = new List<Vector3>(); List<Vector2> uvs = new List<Vector2>(); List<int> triangles = new List<int>(); for (int x = 0; x < 40; x++) { for (int y = 0; y < 40; y++) { vertices.Add(new Vector3((x - 20) / 5.0, (y - 20) / 10.0, 0)); uvs.Add(new Vector2(x / 39.0, 1 - y / 39.0)); if (y == 39 || x == 39) continue; triangles.Add(x * 40 + y); triangles.Add((x + 1) * 40 + y); triangles.Add((x + 1) * 40 + y + 1); triangles.Add(x * 40 + y); triangles.Add((x + 1) * 40 + y + 1); triangles.Add(x * 40 + y + 1); } } flagVertices = new VBO<Vector3>(vertices.ToArray()); flagUVs = new VBO<Vector2>(uvs.ToArray()); flagTriangles = new VBO<int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer); // 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 11"); watch = System.Diagnostics.Stopwatch.StartNew(); Glut.glutMainLoop(); }