Ejemplo n.º 1
0
 public override void Draw(int viewPortWidth, int viewPortHeight)
 {
     UserProgram(_program);
     Gl.ClearColor(0.0f, 0.5f, 1.0f, 1.0f);
     Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
     Gl.BindTexture(TextureTarget.Texture2d, _texture1);
     base.Draw(viewPortWidth, viewPortHeight);
     Gl.BindVertexArray(_vertexAttrObject);
     Gl.DrawArrays(PrimitiveType.Triangles, 0, _figureResult.Figure.Length);
 }
Ejemplo n.º 2
0
        static void WindowRefreshCallback(Glfw.Window window)
        {
            var slot = m_Slots[window];
            Log("{0} to {1} at {2}: Window refresh",
                m_Counter++, slot.Number, Glfw.GetTime());

            Glfw.MakeContextCurrent(window);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            Glfw.SwapBuffers(window);
        }
Ejemplo n.º 3
0
        private void RenderFramebufferToScreen()
        {
            Gl.Viewport(0, 0, Constants.windowWidth, Constants.windowHeight);
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            framebufferRenderShader.SetFloat("exposure", Constants.exposure);
            framebufferRenderPlane.Draw(framebufferRenderShader, mainFramebuffer.ColorTexture);
        }
Ejemplo n.º 4
0
        public void ClearFrameBuffer(float r, float g, float b, float a)
        {
            FrameBuffer.Bind();

            Gl.ClearColor(r, g, b, a);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            FrameBuffer.Unbind();
        }
Ejemplo n.º 5
0
        private void SurfaceView_Render(object sender, GlSurfaceViewEventArgs e)
        {
            GLSurfaceView glSurfaceView = (GLSurfaceView)sender;

            Gl.Viewport(0, 0, glSurfaceView.Width, glSurfaceView.Height);
            Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Es2_Render();
        }
Ejemplo n.º 6
0
        private static void OnRenderFrame()
        {
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            a += 0.008f;
            DrawChessBoard(0, 0, 0, 90.6f, 90.6f, ChessboardTexrute);                                 //Chessboard
            DrawBox(21.5f, 0.0f, -18.92f, 5.73f, 2.2f, 5.32f, Matrix4.Identity, panelTexture);        //1
            Draw3Corner(26.54f, 2.3f, -18.38f, 4.1f, 5.1f, 5.0f,                                      //2
                        Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 2),              //
                        panelTexture, cornerTexture);                                                 //
            DrawBox(22.03f, 0.0f, -7.39f, 5.12f, 1.9f, 4.51f, Matrix4.Identity, panelTexture);        //3
            DrawBox(23.9f, 1.9f, -6.85f, 2.87f, 3.89f, 2.05f, Matrix4.Identity, panelTexture);        //4
            DrawBox(13.6f, 0.0f, -18.46f, 4.3f, 2.1f, 4.51f, Matrix4.Identity, panelTexture);         //5
            DrawBox(14.5f, 2.1f, -17.82f, 3.0f, 3.4f, 2.87f, Matrix4.Identity, panelTexture);         //6
            DrawBox(12.91f, 0.0f, -6.76f, 4.7f, 1.9f, 4.51f, Matrix4.Identity, panelTexture);         //7
            DrawBox(23.14f, 0.0f, 23.14f, 4.71f, 1.64f, 4.5f, Matrix4.Identity, panelTexture);        //8
            DrawBox(22.84f, 1.64f, 24.24f, 4.51f, 3.8f, 3.28f, Matrix4.Identity, panelTexture);       //9
            DrawBox(25.6f, 0.0f, 31.33f, 3.69f, 1.8f, 5.32f, Matrix4.Identity, panelTexture);         //10
            Draw3Corner(27.85f, 1.8f, 32.97f, 4.1f, 5.1f, 5.0f,                                       //11
                        Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI),                   //
                        panelTexture, cornerTexture);                                                 //
            DrawCross(12.3f, 1.9f, -6.2f, 4.8f, 5f, 3.3f,                                             //12
                      Matrix4.Identity,                                                               //
                      panelTexture, crossTexture);                                                    //
            DrawCross(12.3f, 1.9f, 23.2f, 4.8f, 5f, 3.3f,                                             //13
                      Matrix4.Identity,                                                               //
                      panelTexture, crossTexture);                                                    //
            DrawBox(7.5f, 0.0f, 31.33f, 3.69f, 6.3f, 5.32f, Matrix4.Identity, panelTexture);          //14
            DrawBox(13.2f, 0.0f, 31.33f, 3.69f, 5.5f, 5.32f, Matrix4.Identity, panelTexture);         //15
            DrawBox(2.9f, 0.0f, 1.3f, 4.7f, 1.9f, 4.51f, Matrix4.Identity, panelTexture);             //16
            DrawBox(3.6f, 1.9f, 2.1f, 4.9f, 5.0f, 3.3f, Matrix4.Identity, panelTexture);              //17
            DrawBox(4.0f, 6.9f, 3.5f, 4.0f, 3.0f, 2.7f,                                               //18
                    Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4), panelTexture);    //
            DrawBox(3.6f, 1.7f, 12.8f, 4.9f, 5.0f, 3.3f, Matrix4.Identity, panelTexture);             //19
            DrawBox(4.0f, 6.7f, 14.2f, 4.0f, 3.0f, 2.7f,                                              //20
                    Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4), panelTexture);    //
            DrawBox(-7.4f, 0.0f, 1.3f, 5.7f, 1.9f, 6.5f, Matrix4.Identity, panelTexture);             //21
            DrawCylinder(-4.55f, 1.9f, 4.55f, 2.35f, 5, 30,                                           //22
                         Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 2),             //
                         cyrcleTexture, panelTexture);                                                //
            DrawBox(-7.4f, 0.0f, 11.0f, 5.7f, 1.9f, 6.5f, Matrix4.Identity, panelTexture);            //23
            DrawCylinder(-4.55f, 1.9f, 13.95f, 2.35f, 5, 30,                                          //24
                         Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 2),             //
                         cyrcleTexture, panelTexture);                                                //
            DrawSphere(-4.55f, 8.5f, 4.55f, 1.9f, n,                                                  //25
                       Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI), sphereTexture);   //
            DrawSphere(-4.55f, 8.5f, 14.1f, 1.9f, n,                                                  //26
                       Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI), sphereTexture);   //
            DrawBox(-23f, 0.0f, 20.2f, 4.3f, 2.1f, 4.51f, Matrix4.Identity, panelTexture);            //27
            DrawBox(-22f, 2.1f, 20.2f, 3.0f, 3.4f, 2.87f, Matrix4.Identity, panelTexture);            //28
            DrawBox(-22f, 2.1f, 25.2f, 5.5f, 4.5f, 2.87f, Matrix4.Identity, panelTexture);            //28

            //DrawSphere(20, 5, -30, 3, n, Matrix4.CreateFromAxisAngle(Vector3.UnitY, -a), sphereTexture);
            Glut.glutSwapBuffers();
        }
Ejemplo n.º 7
0
        public override void Draw(int viewPortWidth, int viewPortHeight)
        {
            UserProgram(_program);
            Gl.ClearColor(0.0f, 0.5f, 1.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            base.Draw(viewPortWidth, viewPortHeight);
            int vertexCount = _figureResult.Figure.Length / _figureResult.VertexPerLineCount;

            Gl.BindVertexArray(_vertexAttrObject);
            Gl.DrawArrays(PrimitiveType.Triangles, 0, vertexCount);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Clears the render context with a certain color and alpha value. Since this also
        /// clears the stencil buffer, the stencil reference value is also reset to '0'.
        /// </summary>
        public void Clear(uint rgb = 0, float alpha = 0.0f)
        {
            ApplyRenderTarget();

            float red   = ColorUtil.GetR(rgb) / 255.0f;
            float green = ColorUtil.GetG(rgb) / 255.0f;
            float blue  = ColorUtil.GetB(rgb) / 255.0f;

            Gl.ClearColor(red, green, blue, alpha);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.DepthBufferBit);
        }
Ejemplo n.º 9
0
        // Render loop
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender;
            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ERROR_CODE err = ERROR_CODE.FAILURE;

            if (viewer.isAvailable() && zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                if (zedMat.IsInit())
                {
                    // Retrieve left image
                    err = zedCamera.RetrieveImage(zedMat, sl.VIEW.LEFT, sl.MEM.CPU);
                    // Update pose data (used for projection of the mesh over the current image)
                    tracking_state = zedCamera.GetPosition(ref cam_pose);

                    if (tracking_state == POSITIONAL_TRACKING_STATE.OK)
                    {
                        timer++;
                        if (userAction.hit)
                        {
                            Vector2 imageClick = new Vector2((float)userAction.hitCoord.X * (float)zedCamera.ImageWidth, (float)userAction.hitCoord.Y * (float)zedCamera.ImageHeight);
                            findPlaneStatus = zedCamera.findPlaneAtHit(ref plane, imageClick);
                            if (findPlaneStatus == ERROR_CODE.SUCCESS)
                            {
                                zedCamera.convertHitPlaneToMesh(planeMeshVertices, planeMeshTriangles, out nbVertices, out nbTriangles);
                            }
                            userAction.clear();
                        }
                        //if 500ms have spend since last request (for 60fps)
                        if (timer % 30 == 0 && userAction.pressSpace)
                        {
                            // Update pose data (used for projection of the mesh over the current image)
                            Quaternion priorQuat  = Quaternion.Identity;
                            Vector3    priorTrans = Vector3.Zero;
                            findPlaneStatus = zedCamera.findFloorPlane(ref plane, out float playerHeight, priorQuat, priorTrans);

                            if (findPlaneStatus == ERROR_CODE.SUCCESS)
                            {
                                zedCamera.convertFloorPlaneToMesh(planeMeshVertices, planeMeshTriangles, out nbVertices, out nbTriangles);
                            }
                            userAction.clear();
                        }
                    }
                    if (findPlaneStatus == ERROR_CODE.SUCCESS)
                    {
                        viewer.updateMesh(planeMeshVertices, planeMeshTriangles, nbVertices, nbTriangles, plane.Type, plane.Bounds, userAction);
                    }
                    viewer.updateImageAndState(zedMat, cam_pose, tracking_state);
                    viewer.render();
                }
            }
        }
Ejemplo n.º 10
0
        protected override void OnDraw()
        {
            // Clear Depth Buffer
            Gl.Clear(ClearBufferMask.DepthBufferBit);

            // Get camera matrix
            Camera   camera       = SceneManager.Instance.CurrentScene.CurCamera;
            Matrix4f cameraMatrix = camera.Perspective * camera.View;

            DrawEntities(cameraMatrix);
        }
Ejemplo n.º 11
0
        private static void OnRenderFrame()
        {
            // set up the OpenGL viewport and clear both the color and depth bits
            Gl.Viewport(0, 0, Window.Width, Window.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // draw the user interface after everything else
            OpenGL.UI.UserInterface.Draw();

            // finally, swap the back buffer to the front so that the screen displays
            Window.SwapBuffers();
        }
Ejemplo n.º 12
0
        // method called when Render is requested via Invalidate
        private void glControl1_Render(object sender, OpenGL.GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GraphicsHandler.SetDrawingColor1();
            GcodeHandler.RedrawFullPicture();
            GraphicsHandler.SetDrawingColor2();
            GcodeHandler.RedrawCompletedPicture();
        }
Ejemplo n.º 13
0
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            using (var lastFrame = visualizerData.TakeFrameWithOwnership())
            {
                if (lastFrame == null)
                {
                    return;
                }

                NativeWindow nativeWindow = (NativeWindow)sender;

                Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                // Update model/view/projective matrices in shader
                var proj = Matrix4x4.CreatePerspectiveFieldOfView(ToRadians(65.0f), (float)nativeWindow.Width / nativeWindow.Height, 0.1f, 150.0f);
                var view = Matrix4x4.CreateLookAt(Vector3.Zero, Vector3.UnitZ, -Vector3.UnitY);

                SphereRenderer.View       = view;
                SphereRenderer.Projection = proj;

                CylinderRenderer.View       = view;
                CylinderRenderer.Projection = proj;

                PointCloudRenderer.View       = view;
                PointCloudRenderer.Projection = proj;

                PointCloud.ComputePointCloud(lastFrame.Capture.Depth, ref pointCloud);
                PointCloudRenderer.Render(pointCloud, new Vector4(1, 1, 1, 1));

                for (uint i = 0; i < lastFrame.NumberOfBodies; ++i)
                {
                    var skeleton  = lastFrame.GetBodySkeleton(i);
                    var bodyId    = lastFrame.GetBodyId(i);
                    var bodyColor = BodyColors.GetColorAsVector(bodyId);

                    for (int jointId = 0; jointId < (int)JointId.Count; ++jointId)
                    {
                        var joint = skeleton.GetJoint(jointId);

                        // Render the joint as a sphere.
                        const float radius = 0.024f;
                        SphereRenderer.Render(joint.Position / 1000, radius, bodyColor);

                        if (JointConnections.JointParent.TryGetValue((JointId)jointId, out JointId parentId))
                        {
                            // Render a bone connecting this joint and its parent as a cylinder.
                            CylinderRenderer.Render(joint.Position / 1000, skeleton.GetJoint((int)parentId).Position / 1000, bodyColor);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        private void GraphicsControl_Draw(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext  ctx = e.Context;
            IGraphicsSurface fb  = e.Framebuffer;

            Gl.Viewport(0, 0, (int)fb.Width, (int)fb.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ctx.Bind(_Program);
            _Program.SetUniform(ctx, "hal_ModelViewProjection", new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f));
            _VertexArray.Draw(ctx, _Program);
        }
Ejemplo n.º 16
0
        public void Run()
        {
            while (GLFW.WindowShouldClose(window) == 0)
            {
                Gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                // Drawing

                GLFW.SwapBuffers(window);
                GLFW.PollEvents();
            }
        }
Ejemplo n.º 17
0
        public void RenderFramebuffer()
        {
            var cameraComponent = MainCamera.GetComponent <CameraComponent>();

            Gl.Viewport(0, 0, GameSettings.GameResolutionX, GameSettings.GameResolutionY);
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            Gl.ClearDepth(1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            framebufferRenderShader.SetFloat("exposure", RenderManager.Instance.exposure);
            framebufferRenderShader.SetInt("tonemapOperator", (int)RenderManager.Instance.tonemapOperator);
            framebufferRenderPlane.Draw(framebufferRenderShader, cameraComponent.Framebuffer.ColorTexture);
        }
Ejemplo n.º 18
0
        private void glControl_Render(object sender, GlControlEventArgs e)
        {
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Gl.Begin(PrimitiveType.Polygon);
            Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.5f, 0.1f);
            Gl.Color3(1.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.333333f);
            Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.666666f);
            Gl.Color3(0.0f, 1.0f, 1.0f); Gl.Vertex2(0.5f, 0.9f);
            Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.666666f);
            Gl.Color3(1.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.333333f);
            Gl.End();
        }
Ejemplo n.º 19
0
        public static void Tick(FrameState state)
        {
            Gl.Clear(Gl.ClearBufferMask.Color);
            Gl.DrawArrays(Gl.PrimitiveType.Triangles, 0, 3);
            Sdl.Gl.SwapWindow(Application.window);

            /*
             * if (Application.inputs.Mouse.Left.IsPressed)
             * {
             *  Console.WriteLine("left mouse button is pressed");
             * }
             */
        }
Ejemplo n.º 20
0
        static void Main()
        {
            try {
                string envDebug = Environment.GetEnvironmentVariable("DEBUG");
                if (envDebug == "GL")
                {
                    KhronosApi.Log += delegate(object sender, KhronosLogEventArgs e) {
                        Console.WriteLine(e.ToString());
                    };
                    KhronosApi.LogEnabled = true;
                }

                // RPi runs on EGL
                Egl.IsRequired = true;

                if (Egl.IsAvailable == false)
                {
                    throw new InvalidOperationException("EGL is not available. Aborting.");
                }

                using (VideoCoreWindow nativeWindow = new VideoCoreWindow()) {
                    using (DeviceContext eglContext = DeviceContext.Create(nativeWindow.Display, nativeWindow.Handle)) {
                        eglContext.ChoosePixelFormat(new DevicePixelFormat(32));

                        IntPtr glContext = eglContext.CreateContext(IntPtr.Zero);

                        eglContext.MakeCurrent(glContext);

                        Initialize();

                        Gl.Viewport(0, 0, 1920, 1080);
                        Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);

                        while (true)
                        {
                            Gl.Clear(ClearBufferMask.ColorBufferBit);
                            Draw();
                            eglContext.SwapBuffers();
                            break;
                        }

                        System.Threading.Thread.Sleep(10000);

                        Terminate();
                        eglContext.DeleteContext(glContext);
                    }
                }
            } catch (Exception exception) {
                Console.WriteLine(exception.ToString());
            }
        }
Ejemplo n.º 21
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // 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;
            }

            // 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);
            Gl.BindTexture(glassTexture);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
            program["enable_lighting"].SetValue(lighting);

            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeQuads);

            Gl.DrawElements(BeginMode.Quads, cubeQuads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Glut.glutSwapBuffers();
        }
Ejemplo n.º 22
0
        private static void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            NativeWindow nativeWindow = (NativeWindow)sender;

            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Gl.UseProgram(_CubeEdgeProgram);

            // Compute MVP
            PerspectiveProjectionMatrix proj = new PerspectiveProjectionMatrix(60.0f, (float)nativeWindow.Width / nativeWindow.Height, 0.5f, 1e6f);
            ModelMatrix view  = new ModelMatrix();
            ModelMatrix model = new ModelMatrix();

            model.RotateY(_Angle);
            model.RotateZ(_Angle);

            view.LookAtTarget(Vertex3f.One * 7.0f, Vertex3f.Zero, Vertex3f.UnitY);

            Gl.BindVertexArray(_CubeVao);

            Gl.UniformMatrix4(_CubeEdgeProgram_Location_uMVP, false, (proj * view * model).ToArray());

            foreach (float scale4d in new float[] { 64.0f, 32.0f, 16.0f, 8.0f, 4.0f, 2.0f, 1.0f, 0.5f, 0.25f, 0.125f })
            {
                Gl.Uniform1(_CubeEdgeProgram_Location_uScale4D, scale4d * _Zooom);
                Gl.Uniform4(_CubeEdgeProgram_Location_uColor, 0.0f, 0.3f, 1.0f, Math.Min(1.0f, scale4d * _Zooom / 2.0f));
                Gl.DrawElements(PrimitiveType.Lines, _CubeEdges.Length, DrawElementsType.UnsignedShort, IntPtr.Zero);
            }

            _Angle += 360.0f / (25.0f * 5);
            _Zooom -= 0.025f;

            if (_Zooom < 0.5f)
            {
                _Zooom = 1.0f;
            }

            // Save PNG frame
            if (_FrameNo < 125)
            {
                using (Bitmap bitmap = new Bitmap((int)nativeWindow.Width, (int)nativeWindow.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) {
                    BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                    Gl.ReadPixels(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height, OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bitmapData.Scan0);

                    bitmap.Save(String.Format("Frame_{0:D3}.png", _FrameNo++));
                }
            }
        }
Ejemplo n.º 23
0
        private static void OnRender()
        {
            //Set up the OpenGL viewport
            Gl.Viewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
            //Clear both the color and depth bits
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            BkgRender();
            CubeRender();

            //Flush buffer to display
            Gl.Flush();
            //Glut.glutSwapBuffers();
        }
Ejemplo n.º 24
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);
            if (IsFrameReady())
            {
                //Trace.WriteLine("Frame done.");
                //break;
                return;
            }
            var sw = Stopwatch.StartNew();

            RayTrace();
            sw.Stop();
            mTimeElapsed += (float)(sw.Elapsed.TotalSeconds);
            mNumFrames++;
            mNumRaysTraced += RaysTracedPerFrame;
            sw.Restart();
            if (mTimeElapsed >= 0.25f)
            {
                float raysPerSec = mNumRaysTraced / mTimeElapsed;
                raysPerSec /= 1000.0f * 1000.0f;

                mText          = string.Format("ray-trace: {0:.00} ms : {1:.00} MRays/sec {2}", mTimeElapsed / mNumFrames * 1000.0f, raysPerSec, GetStats());
                mTimeElapsed   = 0.0f;
                mNumFrames     = 0;
                mNumRaysTraced = 0;
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            // Initialize state
            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(0, 1, 0, 1, -1, 1);
            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();
            Gl.Viewport(0, 0, Width, Height);

            Gl.ClearColor(BackBufferColor.X, BackBufferColor.Y, BackBufferColor.Z, 1);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Display();
            System.Threading.Thread.Sleep(10);

            DrawText(15, 15, mText);
            this.Title = mText;

            sw.Stop();
            mTimeDelta = (float)(sw.Elapsed.TotalSeconds);
        }
Ejemplo n.º 25
0
        public void GameLoop()
        {
            // Initialize OpenGL and GLFW
            Gl.Initialize();
            Glfw.Init();
            // Set Window Hints
            Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL);
            Glfw.WindowHint(Hint.ContextVersionMajor, 4);
            Glfw.WindowHint(Hint.ContextVersionMinor, 6);
            Glfw.WindowHint(Hint.OpenglProfile, Profile.Core);
            Glfw.WindowHint(Hint.Doublebuffer, true);
            Glfw.WindowHint(Hint.Decorated, true);

            Window = Glfw.CreateWindow(Width, Height, WindowTitle,
                                       Monitor.None, Window.None
                                       );
            if (Window == Window.None)
            {
                Console.Error.WriteLine("Failed to create GLFW Window");
                Glfw.Terminate();
                Environment.Exit(1001);
            }

            Glfw.MakeContextCurrent(Window);
            Glfw.SwapInterval(1);

            Gl.Viewport(0, 0, Width, Height);
            Glfw.SetFramebufferSizeCallback(Window, OnResizeCallback);

            Init();

            while (!Glfw.WindowShouldClose(Window))
            {
                PreUpdate();

                Gl.ClearColor(BackgroundColor.red, BackgroundColor.green,
                              BackgroundColor.blue, BackgroundColor.alpha);
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                Draw();
                Update();

                Glfw.SwapBuffers(Window);
                Glfw.PollEvents();
            }

            Quit();

            Glfw.Terminate();
        }
Ejemplo n.º 26
0
        private void Render_Render(object sender, GlControlEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("render");
            //code executed to render the update iguess
            //not sure how this is different to onupdate


            //fill the viewport with a color
            //basically wipe it clean for a new rendering frame
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            //its a matrix. but you dont need to know how matrixes work.
            //the gist of it is that when you multiply a bunch of stuff together you can make 3D
            //opengl does all that hard stuff, you just need to know how to use the function calls

            //the projection matrix turns the 3D space into what your camera sees
            //this particular function tells OpenGL to turn its 3D world into a flat 2D image
            //  that has these dimensions:
            //      100%
            //  100%    100%
            //      100%
            //aka it takes up all of our rendering window.
            Matrix4x4f projection = Matrix4x4f.Ortho2D(-1.0f, 1.0f, -1.0f, 1.0f);

            //the translated matrix moves the model around in 3D space
            //so we'll take our triangle model and move it
            //to apply multiple matrices to something, you just multiple them together
            //so we're multiplying that by a matrix that rotates the model on the Z axis
            Matrix4x4f model = Matrix4x4f.RotatedZ(angleZ) * Matrix4x4f.RotatedY(angleY) * Matrix4x4f.RotatedX(angleX) * Matrix4x4f.Translated(-0.5f, -0.5f, 0.0f);

            //tell OpenGL to use this shader
            Gl.UseProgram(shaderProgram.ProgramID);
            //send a matrix to our shader program. it will send it to the variable in the shader that we located and
            //  saved into attribUniformLoc
            //a uniform is just a variable in the shader that we manually send data to, instead of the shader
            //  reading that data from a buffer in the gpu vram
            //the matrix we're sending is our projection matrix multiplied by our model matrix
            //the model matrix puts the triangle in the right spot in our 3D world, the projection matrix
            //  makes it draw to the camera properly
            Gl.UniformMatrix4f(shaderProgram.attribUniformLoc, 1, false, model * projection);
            //tell OpenGL to use the state data saved in this Vertex Array Object
            Gl.BindVertexArray(vao.VAO_ID);
            //draw the vertexes
            //it takes the data from the activated buffers and processes it according to how we've told it to interpret it
            //we want to draw triangles, so it will connect every set of 3 vertex data points
            //we're starting from position 0 in the buffers, and processing 3 vertexes
            Gl.DrawArrays(PrimitiveType.Triangles, 0, 12);
            //unbind the vao. its good practice to do this, so you dont accidentally change your vao's state
            Gl.BindVertexArray(0);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Runs the engine
        /// </summary>
        public void RunEngine()
        {
            Initialise();

            Start();
            OnStart();
            Debug.InitialiseDebug();

            // The variables for the delta time
            DateTime t1, t2;

            t1 = t2 = DateTime.Now;

            while (running)
            {
                // Calculate the delta time
                t2 = DateTime.Now;
                float elapsedDelta = (float)(t2 - t1).TotalSeconds;
                t1 = t2;

                // Set delta and fos
                Time.DeltaTime = elapsedDelta;
                Time.FPS       = (int)(1.0f / elapsedDelta);

                // Clear color and depth buffer | Set the clear color for each frame
                Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                Gl.ClearColor(0f, 0f, 0.7f, 1.0f);

                OnUpdate();
                Update();

                // Render here
                Draw();

                running = !window.ShouldWindowClose();


                if (Debug.DoDebug)
                {
                    ErrorCode glError = Gl.GetError();
                    if (glError != ErrorCode.NoError)
                    {
                        Debug.Log("Opengl Error: " + glError + glError.ToString(), Debug.DebugLayer.Render, Debug.DebugLevel.Error);
                    }
                }
            }

            window.Destroy();
        }
Ejemplo n.º 28
0
        public static void Draw()
        {
            if (Model == null)
            {
                return;
            }

            Roller.Update();

            if (ViewportIsDirty)
            {
                Gl.Viewport(0, 0, ViewportWidth, ViewportHeight);

                CameraDistance = CAMERA_DISTANCE_RATIO * Model.BoundingRadius;

                ViewportCanonicalScale = 2f / Math.Min(ViewportWidth, ViewportHeight);
                var s = (double)Model.BoundingRadius * ViewportCanonicalScale / 2;

                Gl.MatrixMode(MatrixMode.Projection);
                Gl.LoadIdentity();
                Gl.Frustum(-ViewportWidth * s, ViewportWidth * s, -ViewportHeight * s, ViewportHeight * s, CameraDistance - Model.BoundingRadius, CameraDistance + Model.BoundingRadius);
                //Gl.Ortho(-ViewportWidth * s, ViewportWidth * s, -ViewportHeight * s, ViewportHeight * s, distance - MeshRadious, distance + MeshRadious);
                Gl.Translate(0f, 0f, -CameraDistance);
            }

            Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            Gl.Disable(EnableCap.Normalize);

            Gl.Enable(EnableCap.Multisample);

            Gl.Disable(EnableCap.Blend);
            Gl.Disable(EnableCap.Dither);
            Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            Gl.Enable(EnableCap.Lighting);
            Gl.Enable(EnableCap.Light0);
            Gl.Light(LightName.Light0, LightParameter.Ambient, new[] { 0.8f, 0.8f, 0.8f, 1.0f });
            Gl.Light(LightName.Light0, LightParameter.Specular, new[] { 0.5f, 0.5f, 0.5f, 1.0f });
            Gl.Light(LightName.Light0, LightParameter.Diffuse, new[] { 1.0f, 1.0f, 1.0f, 1.0f });
            Gl.Light(LightName.Light0, LightParameter.Position, new[] { 0.3f, 0.5f, 1.0f, 0.0f });

            Gl.MultMatrix(Roller.getMatrix().ToArray());
            Model.Draw();
        }
Ejemplo n.º 29
0
        public void RenderShadows()
        {
            Gl.Disable(EnableCap.CullFace);

            Gl.Viewport(0, 0, (int)light.ShadowMap.Resolution.x, (int)light.ShadowMap.Resolution.y);
            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, light.ShadowMap.DepthMapFbo);
            Gl.Clear(ClearBufferMask.DepthBufferBit);

            light.Render();
            testModel.DrawShadows(light, depthShader);

            Gl.Enable(EnableCap.CullFace);

            Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
        private void RenderScene(object sender, GlControlEventArgs e)
        {
            if (!this.initialized)
            {
                if (this.BeforeRenderInitialize != null)
                {
                    this.BeforeRenderInitialize();
                }
                Gl.Initialize();
                Gl.ShadeModel(ShadingModel.Flat);
                Gl.Disable(EnableCap.Lighting);
                Gl.Enable(EnableCap.DepthTest);
                Gl.DepthMask(true);
                Gl.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Fastest);
                Gl.Hint(HintTarget.PolygonSmoothHint, HintMode.Fastest);
                Gl.Hint(HintTarget.PointSmoothHint, HintMode.Fastest);
                Gl.Hint(HintTarget.LineSmoothHint, HintMode.Fastest);
                Gl.Hint(HintTarget.TextureCompressionHint, HintMode.Fastest);
                Gl.DepthFunc(DepthFunction.Lequal);
                Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                Gl.Enable(EnableCap.Blend);
                if (this.AfterRenderInitialize != null)
                {
                    this.AfterRenderInitialize();
                }
                this.initialized = true;
            }
            #region Begin Render

            Gl.Viewport(0, 0, this.openGlControl.Width, this.openGlControl.Height);
            Gl.ClearColor(this.ClearColor.Rf, this.ClearColor.Gf, this.ClearColor.Bf, this.ClearColor.Af);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(-1.0, 1.0, 1.0, -1.0, -1.0, 1.0);
            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            #endregion

            if (this.RenderFrame != null)
            {
                this.RenderFrame();
            }
            this.renderPanel.SuspendLayout();
            this.renderPanel.Image = this.CaptureScaledBitmap(this.renderPanel.Width, this.renderPanel.Height);
            this.renderPanel.ResumeLayout();
        }