Пример #1
0
        public static void Init(GLControl glCtrl)
        {
            control = glCtrl;
            control.MakeCurrent();



            GL.ClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.Enable(EnableCap.AlphaTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.Texture2D);
            //GL.Disable(EnableCap.CullFace);

            GL.PointSize(1.0f);

            FloorGrid.Init();
            TexturePreview.Init();
            DefaultTexture.Init();
            //TextureCamera.Size = new Vector2(DefaultTexture.Width * 1.0f, DefaultTexture.Height * 1.0f);
        }
Пример #2
0
        public static void Render()
        {
            control.MakeCurrent();

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

            Timer.Stop();
            DeltaTime = (float)Timer.Elapsed.Milliseconds;
            Timer.Reset();
            Timer.Start();


            bool isTextureCamera = false;

            if (ViewMode == VIEW_MODE_UV)
            {
                isTextureCamera = true;
            }
            else if (ViewMode == VIEW_MODE_3D)
            {
                if (SelectedItemTag != null)
                {
                    if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_TEXTURE)
                    {
                        isTextureCamera = true;
                    }
                }
            }

            /*
             * if(ViewMode == VIEW_MODE_3D)
             * {
             *      Vector3 CamTarget = Camera.Target;
             *      float velocity = MovementSpeed;
             *      if(ShiftModifier != KeyStatus.Up) velocity *= 0.25f;
             *      velocity *= DeltaTime;
             *
             *      if(MoveForward != KeyStatus.Up)
             *      {
             *              CamTarget.Z -= velocity;
             *      }
             *      if(MoveBackward != KeyStatus.Up)
             *      {
             *              CamTarget.Z += velocity;
             *      }
             *
             *      if(MoveLeft != KeyStatus.Up)
             *      {
             *              CamTarget.X -= velocity;
             *      }
             *      if(MoveRight != KeyStatus.Up)
             *      {
             *              CamTarget.X += velocity;
             *      }
             *
             *      if(MoveUp != KeyStatus.Up)
             *      {
             *              CamTarget.Y -= velocity;
             *      }
             *
             *      if(MoveDown != KeyStatus.Up)
             *      {
             *              CamTarget.Y += velocity;
             *      }
             *      Camera.Target = CamTarget;
             *
             *      float keyZoom = 0.0075f;
             *      float distToZoom = DeltaTime * keyZoom;
             *      if(ShiftModifier != KeyStatus.Up) distToZoom *= 0.25f;
             *
             *      if(ZoomIn != KeyStatus.Up)
             *      {
             *              Camera.Distance -= distToZoom;
             *      }
             *
             *      if(ZoomOut != KeyStatus.Up)
             *      {
             *              Camera.Distance += distToZoom;
             *      }
             *
             *      if(ResetCamera_Key != KeyStatus.Up)
             *      {
             *              Camera.Position = Vector3.Zero;
             *      }
             * }
             * else if(ViewMode == VIEW_MODE_UV)
             * {
             *      float velocity = MovementSpeed * 0.25f;
             *      if(ShiftModifier != KeyStatus.Up) velocity *= 0.25f;
             *      velocity *= DeltaTime;
             *
             *      if(MoveForward != KeyStatus.Up)
             *      {
             *              TextureCamera.Position.Y -= velocity;
             *      }
             *      if(MoveBackward != KeyStatus.Up)
             *      {
             *              TextureCamera.Position.Y += velocity;
             *      }
             *
             *      if(MoveLeft != KeyStatus.Up)
             *      {
             *              TextureCamera.Position.X -= velocity;
             *      }
             *      if(MoveRight != KeyStatus.Up)
             *      {
             *              TextureCamera.Position.X += velocity;
             *      }
             *
             *
             *      float keyZoom = 0.0000025f;
             *      float distToZoom = DeltaTime * keyZoom;
             *
             *      if(ShiftModifier != KeyStatus.Up) distToZoom *= 0.25f;
             *      if(ZoomIn != KeyStatus.Up)
             *      {
             *              TextureCamera.Zoom -= distToZoom;
             *      }
             *
             *      if(ZoomOut != KeyStatus.Up)
             *      {
             *              TextureCamera.Zoom += distToZoom;
             *      }
             *
             *      if(ResetCamera != KeyStatus.Up)
             *      {
             *              TextureCamera.Position = Vector3.Zero;
             *      }
             * }
             */

            if (isTextureCamera)
            {
                float velocity = MovementSpeed * 0.25f;
                if (ShiftModifier != KeyStatus.Up)
                {
                    velocity *= 0.25f;
                }
                velocity *= DeltaTime;

                if (MoveForward != KeyStatus.Up)
                {
                    TextureCamera.Position.Y -= velocity;
                }
                if (MoveBackward != KeyStatus.Up)
                {
                    TextureCamera.Position.Y += velocity;
                }

                if (MoveLeft != KeyStatus.Up)
                {
                    TextureCamera.Position.X -= velocity;
                }
                if (MoveRight != KeyStatus.Up)
                {
                    TextureCamera.Position.X += velocity;
                }

                float keyZoom    = 0.0000025f;
                float distToZoom = DeltaTime * keyZoom;

                if (ShiftModifier != KeyStatus.Up)
                {
                    distToZoom *= 0.25f;
                }
                if (ZoomIn != KeyStatus.Up)
                {
                    TextureCamera.Zoom -= distToZoom;
                }

                if (ZoomOut != KeyStatus.Up)
                {
                    TextureCamera.Zoom += distToZoom;
                }


                if (ResetCamera != KeyStatus.Up)
                {
                    TextureCamera.Position = Vector3.Zero;
                }
            }
            else
            {
                //Vector3 CamTarget = Camera.Target;
                float velocity = MovementSpeed;
                if (ShiftModifier != KeyStatus.Up)
                {
                    velocity *= 0.25f;
                }
                velocity *= DeltaTime;

                /*
                 * if(MoveForward != KeyStatus.Up)
                 * {
                 *      CamTarget.Z -= velocity;
                 * }
                 * if(MoveBackward != KeyStatus.Up)
                 * {
                 *      CamTarget.Z += velocity;
                 * }
                 *
                 * if(MoveLeft != KeyStatus.Up)
                 * {
                 *      CamTarget.X -= velocity;
                 * }
                 * if(MoveRight != KeyStatus.Up)
                 * {
                 *      CamTarget.X += velocity;
                 * }
                 *
                 * if(MoveUp != KeyStatus.Up)
                 * {
                 *      CamTarget.Y -= velocity;
                 * }
                 * if(MoveDown != KeyStatus.Up)
                 * {
                 *      CamTarget.Y += velocity;
                 * }
                 */

                var camMovement = new Vector3(0.0f, 0.0f, 0.0f);

                if (MoveForward != KeyStatus.Up)
                {
                    camMovement.Z += velocity;
                }
                if (MoveBackward != KeyStatus.Up)
                {
                    camMovement.Z -= velocity;
                }

                if (MoveLeft != KeyStatus.Up)
                {
                    camMovement.X -= velocity;
                }

                if (MoveRight != KeyStatus.Up)
                {
                    camMovement.X += velocity;
                }

                if (MoveUp != KeyStatus.Up)
                {
                    camMovement.Y -= velocity;
                }

                if (MoveDown != KeyStatus.Up)
                {
                    camMovement.Y += velocity;
                }


                if (ControlModifier != KeyStatus.Up)
                {
                    Camera.MoveAxial(camMovement);
                }
                else
                {
                    Camera.MoveDirectional(camMovement);
                }


                if (ResetCamera != KeyStatus.Up)
                {
                    Camera.Target = Vector3.Zero;
                }

                //Camera.Target = CamTarget;

                float distToZoom = 0.0075f;
                if (ShiftModifier != KeyStatus.Up)
                {
                    distToZoom *= 0.25f;
                }
                distToZoom *= DeltaTime;

                if (ZoomIn != KeyStatus.Up)
                {
                    Camera.Distance -= distToZoom;
                }
                if (ZoomOut != KeyStatus.Up)
                {
                    Camera.Distance += distToZoom;
                }
            }


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

            SetViewport();

            Matrix4 CamMtx = Matrix4.Identity;

            if (ViewMode == VIEW_MODE_3D)
            {
                CamMtx = Camera.GetMatrix();
            }
            else if (ViewMode == VIEW_MODE_UV)
            {
                CamMtx = TextureCamera.GetMatrix(new Vector2(control.Width * 1.0f, control.Height * 1.0f));
            }
            Matrix4 ProjViewMtx = CamMtx * ProjectionMatrix;

            //TODO: Rendering code here.

            bool noRenderGrid = false;

            if (ViewMode == VIEW_MODE_3D)
            {
                if (SelectedItemTag != null)
                {
                    if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_TEXTURE)
                    {
                        Texture tmpTexture = SelectedItemTag.File.GetTexture(SelectedItemTag.ObjectID);
                        if (tmpTexture != null)
                        {
                            CamMtx = TextureCamera.GetMatrix(new Vector2(control.Width * 1.0f, control.Height * 1.0f));
                            float texW = 1.0f;
                            float texH = 1.0f;

                            Texture.GetTextureAspect(tmpTexture.Width, tmpTexture.Height, out texW, out texH);

                            TexturePreview.Render(CamMtx, tmpTexture.GLID, texW, texH);
                            noRenderGrid = true;
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH)
                    {
                        var tmpRenderGraphItem = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRenderGraphItem != null)
                        {
                            tmpRenderGraphItem.Render(ProjViewMtx, -1);
                            //else tmpRenderGraphItem.Render(ProjViewMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_TRIANGLE_STRIP)
                    {
                        var tmpRenderGraph = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRenderGraph != null)
                        {
                            tmpRenderGraph.Render(ProjViewMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_VERTEX_BATCH)
                    {
                        var tmpRenderGraph = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRenderGraph != null)
                        {
                            tmpRenderGraph.RenderVertexBatch(ProjViewMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_MATERIAL)
                    {
                        var tmpRenderGraph = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRenderGraph != null)
                        {
                            tmpRenderGraph.RenderMaterial(ProjViewMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                }



                if (!noRenderGrid)
                {
                    FloorGrid.Render(Matrix4.CreateTranslation(0.0f, 0.0f, 0.0f) * ProjViewMtx);
                }
            }
            else if (ViewMode == VIEW_MODE_UV)
            {
                float texW      = 1.0f;
                float texH      = 1.0f;
                int   textureID = DefaultTexture.GLID;

                if (SelectedItemTag != null)
                {
                    if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_TEXTURE)
                    {
                        Texture tmpTexture = SelectedItemTag.File.GetTexture(SelectedItemTag.ObjectID);
                        if (tmpTexture != null)
                        {
                            textureID = tmpTexture.GLID;
                            Texture.GetTextureAspect(tmpTexture.Width, tmpTexture.Height, out texW, out texH);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_TRIANGLE_STRIP)
                    {
                        //TexturePreview.Render(CamMtx, DefaultTexture.GLID, 1.0f, 1.0f);
                        var tmpRG = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRG != null)
                        {
                            var tmpTB = tmpRG.GetTriangleBatch(SelectedItemTag.SubObjectID);
                            if (tmpTB != null)
                            {
                                var tmpMat     = tmpRG.GetMaterial(tmpTB.MaterialID);
                                var tmpTexture = SelectedItemTag.File.GetTexture(tmpMat.textureID);
                                textureID = tmpTexture.GLID;
                            }

                            tmpRG.RenderTriangleStripUVs(CamMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_VERTEX_BATCH)
                    {
                        //TexturePreview.Render(CamMtx, DefaultTexture.GLID, 1.0f, 1.0f);
                        var tmpRG = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRG != null)
                        {
                            tmpRG.RendeVertexBatchUVs(CamMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                    else if (SelectedItemTag.ObjectType == TreeNodeTag.OBJECT_TYPE_RENDERGRAPH_MATERIAL)
                    {
                        var tmpRG = SelectedItemTag.File.GetRenderGraph(SelectedItemTag.ObjectID);
                        if (tmpRG != null)
                        {
                            var tmpMat     = tmpRG.GetMaterial(SelectedItemTag.SubObjectID);
                            var tmpTexture = SelectedItemTag.File.GetTexture(tmpMat.textureID);
                            textureID = tmpTexture.GLID;

                            tmpRG.RenderMaterialUVs(CamMtx, SelectedItemTag.SubObjectID);
                        }
                    }
                }

                TexturePreview.Render(CamMtx, textureID, texW, texH);
            }


            control.SwapBuffers();
        }
Пример #3
0
 public static void DeInit()
 {
     FloorGrid.DeInit();
     TexturePreview.DeInit();
     DefaultTexture.DeInit();
 }