private static void OnRenderFrame() { watch.Stop(); float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency; watch.Restart(); // set up the viewport and clear the previous depth and color buffers Gl.Viewport(0, 0, width, height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // make sure the shader program and texture are being used Gl.UseProgram(program.ProgramID); Gl.BindTexture(particleTexture); // update our particle list for (int i = 0; i < particles.Count; i++) { particles[i].Update(deltaTime); //if (particles[i].Life < 0) particles[i] = new Particle(Vector3.Zero); if (particles[i].Life < 0) { particles[i] = new Particle(new Vector3((float)generator.NextDouble() * 200 - 100, 6, 0)); } particlePositions[i] = particles[i].Position; } // delete our previous particle positions (if applicable) and then create a new VBO if (particleVertices != null) { particleVertices.Dispose(); } particleVertices = new VBO <Vector3>(particlePositions); // bind the VBOs to their shader attributes Gl.BindBufferToShaderAttribute(particleVertices, program, "vertexPosition"); Gl.BindBufferToShaderAttribute(particleColors, program, "vertexColor"); Gl.BindBuffer(particlePoints); // enable point sprite mode (which enables the gl_PointCoord value) Gl.Enable(EnableCap.PointSprite); Gl.DrawElements(BeginMode.Points, particlePoints.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.Disable(EnableCap.PointSprite); // bind the font program as well as the font texture Gl.UseProgram(fontProgram.ProgramID); Gl.BindTexture(font.FontTexture); // draw the tutorial information, which is static information.Draw(); Glut.glutSwapBuffers(); }
private static void OnRenderFrame() { watch.Stop(); float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency; watch.Restart(); // set up the viewport and clear the previous depth and color buffers Gl.Viewport(0, 0, width, height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // perform rotation of the cube depending on the keyboard state if (autoRotate) { xangle += deltaTime / 2; yangle += deltaTime; } if (right) { yangle += deltaTime; } if (left) { yangle -= deltaTime; } if (up) { xangle -= deltaTime; } if (down) { xangle += deltaTime; } // make sure the shader program and texture are being used Gl.UseProgram(program); Gl.ActiveTexture(TextureUnit.Texture1); Gl.BindTexture(brickNormals); Gl.ActiveTexture(TextureUnit.Texture0); Gl.BindTexture(brickDiffuse); // set up the model matrix and draw the cube program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle)); program["enable_lighting"].SetValue(lighting); program["enable_mapping"].SetValue(normalMapping); Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition"); Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal"); Gl.BindBufferToShaderAttribute(cubeTangents, program, "vertexTangent"); Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV"); Gl.BindBuffer(cubeTriangles); Gl.DrawElements(BeginMode.Triangles, cubeTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); // bind the font program as well as the font texture Gl.UseProgram(fontProgram.ProgramID); Gl.BindTexture(font.FontTexture); // draw the tutorial information, which is static information.Draw(); Glut.glutSwapBuffers(); }