Exemple #1
0
        private void renderControl_Render(object sender, EventArgs e)
        {
            this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1} FPS", Application.ProductName, Core.CurrentFramesPerSecond);

            RenderControl renderControl = (sender as RenderControl);

            if (takeScreenshot)
            {
                GL.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
            }

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            // OpenTK GLControl focus checking is GARBAGE, might as well leave the check here off -.-
            if (renderControl.Focused)
            {
                OpenTK.Input.KeyboardState kbdState = OpenTK.Input.Keyboard.GetState();

                if (kbdState[OpenTK.Input.Key.Q])
                {
                    sunAngle += Core.DeltaTime / 15.0f;
                }
                if (kbdState[OpenTK.Input.Key.E])
                {
                    sunAngle -= Core.DeltaTime / 15.0f;
                }

                lastKbd = kbdState;

                camera.Update(Core.DeltaTime);
            }

            if (wireframe)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }
            else
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            }

            if (culling)
            {
                GL.Enable(EnableCap.CullFace);
            }
            else
            {
                GL.Disable(EnableCap.CullFace);
            }

            if (shader != null)
            {
                Matrix4 tempMatrix = modelviewMatrix * camera.GetViewMatrix();
                shader.SetUniformMatrix(modelviewMatrixName, false, tempMatrix);

                shader.SetUniform(sunPositionName, new Vector3((float)(Math.Cos(sunAngle * Math.PI / 180.0) * 70.0f), (float)(Math.Sin(sunAngle * Math.PI / 180.0) * 70.0f), 0.0f));
                shader.SetUniform(enableLightName, Convert.ToInt32(lighting));
            }

            if (meshes != null)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

                shader.SetUniform(discardOpaqueName, 0);
                foreach (Mesh mesh in meshes)
                {
                    mesh.Render();
                }
                shader.SetUniform(discardOpaqueName, 1);
                foreach (Mesh mesh in meshes)
                {
                    mesh.Render();
                }
            }

            if (!takeScreenshot && font != null)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                StringBuilder builder = new StringBuilder();
                builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0:0} FPS\n", Core.CurrentFramesPerSecond);

                if (meshes != null)
                {
                    builder.AppendLine();
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Camera: WASD & Mouse+Left Button\n");
                    builder.AppendLine();
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Vsync (F1): {0}\n", renderControl.VSync);
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Wireframe (F2): {0}\n", wireframe);
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Culling (F3): {0}\n", culling);
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Lighting (F4): {0}\n", lighting);
                    builder.AppendLine();
                    builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Rotate Light (Q/E)\n");
                }

                font.DrawString(8.0f, 8.0f, builder.ToString());
            }

            if (takeScreenshot)
            {
                renderControl.GrabScreenshot(true).Save(screenshotPath);
                takeScreenshot = false;

                GL.ClearColor(renderControl.BackColor);
            }
        }
Exemple #2
0
        private void renderControl1_Render(object sender, EventArgs e)
        {
            this.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} - {1} FPS", Application.ProductName, Core.CurrentFramesPerSecond);

            RenderControl renderControl = (sender as RenderControl);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            OpenTK.Input.KeyboardState kbdState = OpenTK.Input.Keyboard.GetState();

            if (renderControl.Focused)
            {
                if (kbdState[OpenTK.Input.Key.Escape] && !lastKbd[OpenTK.Input.Key.Escape])
                {
                    Application.Exit();
                }

                if (kbdState[OpenTK.Input.Key.F1] && !lastKbd[OpenTK.Input.Key.F1])
                {
                    renderControl.VSync = !renderControl.VSync;
                }

                if (kbdState[OpenTK.Input.Key.F2] && !lastKbd[OpenTK.Input.Key.F2])
                {
                    wireframe = !wireframe;
                }

                if (kbdState[OpenTK.Input.Key.F3] && !lastKbd[OpenTK.Input.Key.F3])
                {
                    culling = !culling;
                }
            }

            lastKbd = kbdState;

            if (renderControl.ClientRectangle.Contains(this.PointToClient(Control.MousePosition)))
            {
                camera.Update(Core.DeltaTime);
            }

            if (wireframe)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }
            else
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            }

            if (culling)
            {
                GL.Enable(EnableCap.CullFace);
            }
            else
            {
                GL.Disable(EnableCap.CullFace);
            }

            if (shader != null)
            {
                Matrix4 tempMatrix = modelviewMatrix * camera.GetViewMatrix();
                shader.SetUniformMatrix(modelviewMatrixName, false, tempMatrix);
            }

            if (obfBinary != null)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

                if (shader != null)
                {
                    shader.SetUniform("alpha_reference", 0.5f);
                }

                for (int i = 1; i >= 0; i--)
                {
                    if (shader != null)
                    {
                        shader.SetUniform("alpha_doLessThan", (int)i);
                    }

                    if (tsbRenderAll.Checked)
                    {
                        obfBinary.RenderAssets(shader);
                    }
                    else
                    {
                        var selection = tscmbAssets.ComboBox.SelectedItem;
                        obfBinary.RenderAsset(((KeyValuePair <short, ICollection <short> >)selection).Key, shader);
                    }
                }
            }

            if (font != null)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                StringBuilder builder = new StringBuilder();
                builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0:0} FPS\n", Core.CurrentFramesPerSecond);
                builder.AppendLine();
                builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Vsync (F1): {0}\n", renderControl.VSync);
                builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Wireframe (F2): {0}\n", wireframe);
                builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "Culling (F3): {0}\n", culling);

                font.DrawString(8.0f, 8.0f, builder.ToString());
            }
        }