private void RenderTexture(GLControl glControl1, NUT nut) { if (nut == null) { return; } glControl1.MakeCurrent(); GL.Viewport(glControl1.ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.White); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); foreach (NUT.NUD_Texture tex in nut.textures) { RenderTools.DrawTexturedQuad(nut.draw[tex.id], tex.width, tex.height, true, true, true, true, false, true); } glControl1.SwapBuffers(); }
private void RenderTexture(bool justRenderAlpha = false) { if (!tabControl1.SelectedTab.Text.Equals("Textures")) { return; } // Get the selected NUT texture. NutTexture nutTexture = null; int displayTexture = 0; if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0) { int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash; // Display dummy textures from resources. if (Enum.IsDefined(typeof(NUD.DummyTextures), hash)) { displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash]; } else { foreach (NUT n in Runtime.TextureContainers) { if (n.draw.ContainsKey(hash)) { n.getTextureByID(hash, out nutTexture); displayTexture = n.draw[hash]; break; } } } } if (justRenderAlpha) { texAlphaGlControl.MakeCurrent(); GL.Viewport(texAlphaGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true); //RenderTools.DrawNudMaterialSphere(currentMaterialList[currentMatIndex]); texAlphaGlControl.SwapBuffers(); } else { texRgbGlControl.MakeCurrent(); GL.Viewport(texRgbGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1); //RenderTools.DrawNudMaterialSphere(materials[0]); texRgbGlControl.SwapBuffers(); } if (!Runtime.shaders["Texture"].HasCheckedCompilation) { Runtime.shaders["Texture"].DisplayCompilationWarnings("Texture"); } }
private void RenderTexture(bool justRenderAlpha = false) { if (!tabControl1.SelectedTab.Text.Equals("Textures")) { return; } // Get the selected NUT texture. NutTexture nutTexture = null; int displayTexture = 0; if (currentMaterialList[currentMatIndex].entries.ContainsKey("NU_materialHash") && texturesListView.SelectedIndices.Count > 0) { int hash = currentMaterialList[currentMatIndex].textures[texturesListView.SelectedIndices[0]].hash; // Display dummy textures from resources. if (Enum.IsDefined(typeof(NUD.DummyTextures), hash)) { displayTexture = RenderTools.dummyTextures[(NUD.DummyTextures)hash]; } else { foreach (NUT n in Runtime.TextureContainers) { if (n.glTexByHashId.ContainsKey(hash)) { n.getTextureByID(hash, out nutTexture); displayTexture = n.glTexByHashId[hash]; break; } } } } if (justRenderAlpha) { texAlphaGlControl.MakeCurrent(); GL.Viewport(texAlphaGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1, false, false, false, true); texAlphaGlControl.SwapBuffers(); } else { texRgbGlControl.MakeCurrent(); GL.Viewport(texRgbGlControl.ClientRectangle); RenderTools.DrawTexturedQuad(displayTexture, 1, 1); Bitmap image = FramebufferTools.ReadFrameBufferPixels(0, FramebufferTarget.Framebuffer, texRgbGlControl.Width, texRgbGlControl.Height); image.Save(MainForm.executableDir + "\\image.png"); texRgbGlControl.SwapBuffers(); } if (!Runtime.shaders["Texture"].HasCheckedCompilation) { Runtime.shaders["Texture"].DisplayProgramStatus("Texture"); } }
private void RenderTexture() { if (!_loaded || glControl1 == null) { return; } glControl1.MakeCurrent(); GL.Viewport(glControl1.ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); GL.ClearColor(Color.Black); if (textureList.SelectedItem == null) { glControl1.SwapBuffers(); return; } GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); int width = ((NUT_Texture)textureList.SelectedItem).Width; int height = ((NUT_Texture)textureList.SelectedItem).Height; int texture = NUT.draw[((NUT_Texture)textureList.SelectedItem).HASHID]; bool alphaOverride = renderAlpha && !renderR && !renderG && !renderB; RenderTools.DrawTexturedQuad(texture, width, height, renderR, renderG, renderB, renderAlpha, alphaOverride, preserveAspectRatio); glControl1.SwapBuffers(); if (!Runtime.hasCheckedTexShaderCompilation) { Runtime.shaders["Texture"].displayCompilationWarning("Texture"); Runtime.hasCheckedTexShaderCompilation = true; } }
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(); }