Ejemplo n.º 1
0
        public override void OnRenderFrame(float deltaTime)
        {
//            if (msaa) Gl.Enable(EnableCap.Multisample);
//            else Gl.Disable(EnableCap.Multisample);


            // apply our camera view matrix to the shader view matrix (this can be used for all objects in the scene)
            Gl.UseProgram(program);
            program["view_matrix"].SetValue(TheCamera.ViewMatrix);
//            program["model_matrix"].SetValue(Matrix4.Identity);
            program["enable_lighting"].SetValue(theEnvironment.Lighting);

            if (theEnvironment.LightMove)
            {
                theEnvironment.LightDirection = theEnvironment.LightDirection * Matrix4.CreateRotationY(deltaTime);
                program["light_direction"].SetValue(theEnvironment.LightDirection);
            }

            if (thePathVector3 != null)
            {
                ObjPath tempObjPath = new ObjPath("Path", thePathVector3,
                                                  new Vector3[] { thePathVector3[0], thePathVector3.Last() })
                {
                    LineMaterial   = materialPoint,
                    MarkerMaterial = materialLineMarker
                };
                thePaths.AddObject(tempObjPath);
                thePathVector3 = null;
            }


            // now draw the object file
//            if (wireframe) Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            if (wireframe)
            {
                Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }
            if (objMeshs != null)
            {
                foreach (IObjGroup anObjMesh in objMeshs)
                {
                    anObjMesh.Draw();
                }
            }

            // Reset the model matrix
            program["model_matrix"].SetValue(Matrix4.Identity);

            if (true)
            {
                // Draw a small test grid
                double delta = 5;
                double z     = 0.1;
                Gl.PointSize(10);
                // For some reason EnableCap.PointSmooth = ((int)0x0B10), was commented out in OpenGL4CSharp.
                Gl.Enable(EnableCap.PointSmooth);

                // shift the mouse point a bit toward the camera
                Vector3 mousePoint = MouseWorld + ((TheCamera.Position - MouseWorld).Normalize()) * 0.01f;

                Vector3[] vertexData = new[]
                {
                    mousePoint, new Vector3(0, 0, z),
                    new Vector3(delta, z, delta), new Vector3(0, z, delta), new Vector3(delta, z, 0),
                };

                VBO <Vector3> vertices = new VBO <Vector3>(vertexData);

                if (materialPoint != null)
                {
                    materialPoint.Use();
                }

                Gl.BindBufferToShaderAttribute(vertices, program, "vertexPosition");

                Gl.DrawElements(BeginMode.Points, vertices.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
                vertices.Dispose();
                vertices = null;
            }

//            if (theRenderGameObjects != null)
//            {
//                foreach (ObjGameObject renderGameObject in theRenderGameObjects)
//                {
//                    renderGameObject.Draw(program);
//                }
//                Gl.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
//                Gl.BindBuffer(BufferTarget.ArrayBuffer, 0);
//                Gl.UseProgram(0);
//            }

            if (UseObjMap)
            {
                objTileMap.Draw();
            }
        }