Ejemplo n.º 1
0
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="flags">
        /// The flags.
        /// </param>
        /// <returns>
        /// The render.
        /// </returns>
        public override uint Render(CIwModel model, uint flags)
        {
            try
            {
                CIwMaterial material = model.GetMaterial(this.materialId);
                if (material != null)
                {
                    material.Enable();
                }

                S3E.CheckOpenGLStatus();
                GL.Begin(BeginMode.Triangles);
                base.Render(model, flags);
                GL.End();
                if (material != null)
                {
                    material.Disable();
                }

                S3E.CheckOpenGLStatus();
            }
            catch (Exception ex)
            {
                throw;
            }

            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="flags">
        /// The flags.
        /// </param>
        /// <returns>
        /// The render.
        /// </returns>
        public override uint Render(CIwModel model, uint flags)
        {
            CIwMaterial material = model.GetMaterial(this.m_MaterialID);

            if (material != null)
            {
                material.Enable();
            }

            S3E.CheckOpenGLStatus();
            GL.Begin(BeginMode.Triangles);

            var verts     = model.ResolveBlock <CIwModelBlockVerts>();
            var colors    = model.ResolveBlock <CIwModelBlockCols>();
            var normals   = model.ResolveBlock <CIwModelBlockNorms>();
            var indGroups = model.ResolveBlock <CIwModelBlockIndGroups>();

            if (verts != null)
            {
                foreach (var iwModelPrim in this.prims)
                {
                    iwModelPrim.Render(model, flags, verts, indGroups, colors);
                }
            }

            GL.End();
            if (material != null)
            {
                material.Disable();
            }

            S3E.CheckOpenGLStatus();

            return(0);
        }
Ejemplo n.º 3
0
        private void RenderGameScreen(object sender, PaintEventArgs e)
        {
            if (!this.isLoaded)
            {
                return;
            }

            GL.ClearColor(Color.SkyBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            int w = this.glControl.Width;
            int h = this.glControl.Height;

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            int hh = 2000 * h / w;

            GL.Ortho(-2000, 2000, -hh, hh, -2000, 2000); // Верхний левый угол имеет кооординаты(0, 0)
            GL.Viewport(0, 0, w, h);                     // Использовать всю поверхность GLControl под рисование
            S3E.CheckOpenGLStatus();

            GL.Enable(EnableCap.DepthTest);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            this.angle += (float)Math.PI / 200;
            Matrix4 m = Matrix4.CreateRotationY(this.angle);

            GL.LoadMatrix(ref m);
            S3E.CheckOpenGLStatus();
            if (this.@group != null)
            {
                var models = [email protected]("CIwModel");
                if (models != null)
                {
                    for (int i = 0; i < models.Size; ++i)
                    {
                        ((CIwModel)models[i]).Render();

                        // break;
                    }
                }
            }

            ////GL.Color3(Color.Yellow);
            ////GL.Begin(BeginMode.Triangles);
            ////GL.Vertex2(10, 20);
            ////GL.Vertex2(100, 20);
            ////GL.Vertex2(100, 50);
            ////GL.End();
            //
            S3E.CheckOpenGLStatus();

            this.glControl.SwapBuffers();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// The upload.
 /// </summary>
 public void Upload()
 {
     GL.TexImage2D(
         TextureTarget.Texture2D,
         0,
         PixelInternalFormat.Rgb,
         this.Width,
         this.Height,
         0,
         PixelFormat.Rgb,
         PixelType.UnsignedByte,
         this.Pixels);
     S3E.CheckOpenGLStatus();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// The enable.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        public void Enable(int index)
        {
            GL.ActiveTexture(TextureUnit.Texture0 + index);
            GL.Enable(EnableCap.Texture2D);
            S3E.CheckOpenGLStatus();
            GL.BindTexture(TextureTarget.Texture2D, this.GlTexture);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            S3E.CheckOpenGLStatus();

            // GL.Enable(EnableCap.Blend);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The render.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="flags">
        /// The flags.
        /// </param>
        /// <returns>
        /// The render.
        /// </returns>
        public override uint Render(CIwModel model, uint flags)
        {
            CIwMaterial material = model.GetMaterial(this.materialId);

            if (material != null)
            {
                material.Enable();
            }

            GL.Begin(BeginMode.TriangleStrip);
            base.Render(model, flags);
            GL.End();
            S3E.CheckOpenGLStatus();

            if (material != null)
            {
                material.Disable();
            }

            return(0);
        }
Ejemplo n.º 7
0
 private void Upload()
 {
     GL.BindTexture(TextureTarget.Texture2D, this.glTexture);
     S3E.CheckOpenGLStatus();
     this.image.Upload();
 }