// Rendering private void Render() { if (!render) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (Runtime.renderBackGround) { GL.Begin(PrimitiveType.Quads); GL.Color3(Runtime.back1); GL.Vertex2(1.0, 1.0); GL.Vertex2(-1.0, 1.0); GL.Color3(Runtime.back2); GL.Vertex2(-1.0, -1.0); GL.Vertex2(1.0, -1.0); GL.End(); } // set up the viewport projection and send it to GPU if (!OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.S)) { selecting = false; if (glViewport.Focused && glViewport.ClientRectangle.Contains(PointToClient(Cursor.Position))) { cam.Update(); view = cam.getModelViewMatrix() * perspective; } cam.TrackMouse(); } else { if (OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Left) && !selecting) { selecting = true; Vector2 m = getMouseOnViewPort(); sx1 = m.X; sy1 = m.Y; } } GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); GL.LoadMatrix(ref view); // ready to start drawing model stuff GL.MatrixMode(MatrixMode.Modelview); if (Runtime.renderFloor) { RenderTools.drawFloor(); } GL.Enable(EnableCap.Normalize); // These is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); // draw renderable objects foreach (ModelContainer m in draw) { RenderTools.DrawModel(m, view); } GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.DepthFunc(DepthFunction.Less); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Disable(EnableCap.CullFace); // clear the buffer bit so the skeleton // will be drawn on top of everything GL.UseProgram(0); GL.Clear(ClearBufferMask.DepthBufferBit); // drawing the bones foreach (ModelContainer m in draw) { if (m.vbn != null) { RenderTools.DrawVBN(m.vbn); } } // Mouse selection if (selecting) { GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Clear(ClearBufferMask.DepthBufferBit); if (OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { selecting = false; } Vector2 m = getMouseOnViewPort(); GL.Color3(Color.AliceBlue); GL.LineWidth(2f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); } GL.PopAttrib(); glViewport.SwapBuffers(); }
// Rendering private void Render() { if (!render) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); if (Runtime.renderBackGround) { GL.Begin(PrimitiveType.Quads); GL.Color3(back1); GL.Vertex2(1.0, 1.0); GL.Vertex2(-1.0, 1.0); GL.Color3(back2); GL.Vertex2(-1.0, -1.0); GL.Vertex2(1.0, -1.0); GL.End(); } // set up the viewport projection and send it to GPU GL.MatrixMode(MatrixMode.Projection); if (glViewport.Focused && glViewport.ClientRectangle.Contains(PointToClient(Cursor.Position))) { cam.Update(); view = cam.getViewMatrix() * perspective; } cam.TrackMouse(); GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); GL.LoadMatrix(ref view); // ready to start drawing model stuff GL.MatrixMode(MatrixMode.Modelview); RenderTools.drawFloor(Matrix4.CreateTranslation(Vector3.Zero)); GL.Enable(EnableCap.Normalize); // These is critical to have GL.Enable(EnableCap.RescaleNormal); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Enable(EnableCap.LineSmooth); foreach (ModelContainer m in draw) { RenderTools.DrawModel(m, view); } GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.DepthFunc(DepthFunction.Less); GL.AlphaFunc(AlphaFunction.Gequal, 0.1f); GL.Disable(EnableCap.CullFace); GL.UseProgram(0); // clear the buffer bit so the skeleton // will be drawn on top of everything GL.Clear(ClearBufferMask.DepthBufferBit); // drawing the bones foreach (ModelContainer m in draw) { if (m.vbn != null) { RenderTools.DrawVBN(m.vbn); } } GL.PopAttrib(); glViewport.SwapBuffers(); }
private void Render(object sender, PaintEventArgs e) { if (!ReadyToRender) { return; } glViewport.MakeCurrent(); GL.LoadIdentity(); GL.Viewport(glViewport.ClientRectangle); // Push all attributes so we don't have to clean up later GL.PushAttrib(AttribMask.AllAttribBits); // clear the gf buffer GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); // use fixed function pipeline for drawing background and floor grid GL.UseProgram(0); if (MeshList.treeView1.SelectedNode != null) { if (MeshList.treeView1.SelectedNode is BCH_Texture) { GL.PopAttrib(); BCH_Texture tex = ((BCH_Texture)MeshList.treeView1.SelectedNode); RenderTools.DrawTexturedQuad(tex.display, tex.Width, tex.Height, true, true, true, true, false, true); glViewport.SwapBuffers(); return; } if (MeshList.treeView1.SelectedNode is NUT_Texture) { GL.PopAttrib(); NUT_Texture tex = ((NUT_Texture)MeshList.treeView1.SelectedNode); RenderTools.DrawTexturedQuad(((NUT)tex.Parent).draw[tex.HASHID], tex.Width, tex.Height, true, true, true, true, false, true); glViewport.SwapBuffers(); return; } } if (Runtime.renderBackGround) { // background uses different matrices GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); RenderTools.RenderBackground(); } // Camera Update // ------------------------------------------------------------- GL.MatrixMode(MatrixMode.Projection); if (glViewport.ClientRectangle.Contains(glViewport.PointToClient(Cursor.Position)) && glViewport.Focused && CurrentMode == Mode.Normal && !TransformTool.hit) { Camera.Update(); //if (cameraPosForm != null && !cameraPosForm.IsDisposed) // cameraPosForm.updatePosition(); } try { if (OpenTK.Input.Mouse.GetState() != null) { Camera.mouseSLast = OpenTK.Input.Mouse.GetState().WheelPrecise; } } catch { } Matrix4 matrix = Camera.getMVPMatrix(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref matrix); // Floor // ------------------------------------------------------------- if (Runtime.renderFloor) { RenderTools.drawFloor(); } // Shadows // ------------------------------------------------------------- if (Runtime.drawModelShadow) { CalculateLightSource(); // update light matrix and setup shadowmap rendering GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref lightMatrix); GL.Enable(EnableCap.DepthTest); GL.Viewport(0, 0, sw, sh); GL.BindFramebuffer(FramebufferTarget.Framebuffer, sfb); foreach (ModelContainer m in draw) { m.RenderShadow(Camera, 0, Matrix4.Zero, Camera.getMVPMatrix()); } // reset matrices and viewport for model rendering again GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.LoadMatrix(ref matrix); GL.Viewport(glViewport.ClientRectangle); } // render models into hdr buffer // ------------------------------------------------------------- if (Runtime.useDepthTest) { GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); } else { GL.Disable(EnableCap.DepthTest); } GL.Enable(EnableCap.DepthTest); // Models // ------------------------------------------------------------- //frameTime.Start(); if (Runtime.renderModel || Runtime.renderModelWireframe) { foreach (TreeNode m in draw) { if (m is ModelContainer) { ((ModelContainer)m).Render(Camera, 0, Matrix4.Zero, Camera.getMVPMatrix()); } } } if (ViewComboBox.SelectedIndex == 1) { foreach (TreeNode m in draw) { if (m is ModelContainer) { ((ModelContainer)m).RenderPoints(Camera); } } } //GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); /*// render gaussian blur stuff * if (Runtime.drawQuadBlur) * DrawQuadBlur(); * * // render full screen quad for post processing * if (Runtime.drawQuadFinalOutput) * DrawQuadFinalOutput();*/ // use fixed function pipeline again for area lights, lvd, bones, hitboxes, etc SetupFixedFunctionRendering(); /*// draw path.bin * if (Runtime.renderPath) * DrawPathDisplay(); * * // area light bounding boxes should intersect stage geometry and not render on top * if (Runtime.drawAreaLightBoundingBoxes) * DrawAreaLightBoundingBoxes();*/ // clear depth buffer so stuff will render on top of the models GL.Clear(ClearBufferMask.DepthBufferBit); if (Runtime.renderLVD) { _lvd.Render(); } if (Runtime.renderBones) { foreach (ModelContainer m in draw) { m.RenderBones(); } } // ACMD if (ParamManager != null && Runtime.renderHurtboxes && draw.Count > 0 && (draw[0] is ModelContainer)) { ParamManager.RenderHurtboxes(Frame, scriptId, ACMDScript, ((ModelContainer)draw[0]).GetVBN()); } if (ACMDScript != null && draw.Count > 0 && (draw[0] is ModelContainer)) { ACMDScript.Render(((ModelContainer)draw[0]).GetVBN()); } //Debug.WriteLine(frameTime.getAverageRenderTime()); // Bone Transform Tool if (ViewComboBox.SelectedIndex == 2) { if (modeBone.Checked) { TransformTool.Render(Camera, new Ray(Camera, glViewport)); if (TransformTool.state == 1) { CurrentMode = Mode.Selection; } else { CurrentMode = Mode.Normal; } } if (TransformTool.HasChanged()) { if (Animation != null && TransformTool.b != null) { // get the node group for the current bone in animation Animation.KeyNode ThisNode = null; foreach (Animation.KeyNode node in Animation.Bones) { if (node.Text.Equals(TransformTool.b.Text)) { // found ThisNode = node; break; } } if (ThisNode == null) { ThisNode = new Animation.KeyNode(TransformTool.b.Text); Animation.Bones.Add(ThisNode); } // update or add the key frame ThisNode.SetKeyFromBone((float)currentFrame.Value, TransformTool.b); } } } // Mouse selection // ------------------------------------------------------------- if (ViewComboBox.SelectedIndex == 1) { try { if (CurrentMode == Mode.Normal && OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { CurrentMode = Mode.Selection; Vector2 m = GetMouseOnViewport(); sx1 = m.X; sy1 = m.Y; } } catch { } if (CurrentMode == Mode.Selection) { if (!OpenTK.Input.Mouse.GetState().IsButtonDown(OpenTK.Input.MouseButton.Right)) { checkSelect(); CurrentMode = Mode.Normal; } GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); Vector2 m = GetMouseOnViewport(); GL.Color3(Color.Black); GL.LineWidth(2f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); GL.Color3(Color.White); GL.LineWidth(1f); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(sx1, sy1); GL.Vertex2(m.X, sy1); GL.Vertex2(m.X, m.Y); GL.Vertex2(sx1, m.Y); GL.End(); GL.PopMatrix(); } } /*if (CurrentMode == Mode.Photoshoot) * { * freezeCamera = false; * if (Keyboard.GetState().IsKeyDown(Key.W) && Mouse.GetState().IsButtonDown(MouseButton.Left)) * { * shootX = this.PointToClient(Cursor.Position).X; * shootY = this.PointToClient(Cursor.Position).Y; * freezeCamera = true; * } * // Hold on to your pants, boys * RenderTools.DrawPhotoshoot(glViewport, shootX, shootY, shootWidth, shootHeight); * }*/ GL.PopAttrib(); glViewport.SwapBuffers(); }