Exemple #1
0
        public override void DrawSpriteModel(BaseTexture texture, mspriteframe_t frame, Vector3 up, Vector3 right, Vector3 origin)
        {
            GL.Color3(1f, 1, 1);

            this.Device.DisableMultitexture( );

            GL.Enable(EnableCap.Texture2D);

            texture.Bind( );

            GL.Enable(EnableCap.AlphaTest);
            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(0f, 1);
            var point = origin + up * frame.down + right * frame.left;

            GL.Vertex3(point.X, point.Y, point.Z);

            GL.TexCoord2(0f, 0);
            point = origin + up * frame.up + right * frame.left;
            GL.Vertex3(point.X, point.Y, point.Z);

            GL.TexCoord2(1f, 0);
            point = origin + up * frame.up + right * frame.right;
            GL.Vertex3(point.X, point.Y, point.Z);

            GL.TexCoord2(1f, 1);
            point = origin + up * frame.down + right * frame.right;
            GL.Vertex3(point.X, point.Y, point.Z);

            GL.End( );

            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.AlphaTest);
        }
Exemple #2
0
        public override void DrawSequentialPolyMultiTexture(BaseTexture texture, BaseTexture lightMapTexture, byte[] lightMapData, GLPoly p, int lightMapNumber)
        {
            GL.Enable(EnableCap.Texture2D);
            // Binds world to texture env 0
            texture.Bind( );
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( int )TextureEnvMode.Replace);

            // Binds lightmap to texenv 1
            this.Device.EnableMultitexture( ); // Same as SelectTexture (TEXTURE1).
            lightMapTexture.BindLightmap((( GLTextureDesc )lightMapTexture.Desc).TextureNumber + lightMapNumber);
            var i = lightMapNumber;

            if (lightMapTexture.LightMapModified[i])
            {
                lightMapTexture.CommitLightmap(lightMapData, i);
            }

            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( int )TextureEnvMode.Blend);
            GL.Begin(PrimitiveType.Polygon);
            for (i = 0; i < p.numverts; i++)
            {
                var v = p.verts[i];
                GL.MultiTexCoord2(TextureUnit.Texture0, v[3], v[4]);
                GL.MultiTexCoord2(TextureUnit.Texture1, v[5], v[6]);
                GL.Vertex3(v);
            }
            GL.End( );
            GL.Disable(EnableCap.Texture2D);
        }
Exemple #3
0
        public override void DrawSequentialPoly(BaseTexture texture, BaseTexture lightMapTexture, GLPoly p, int lightMapNumber)
        {
            GL.Enable(EnableCap.Texture2D);
            texture.Bind( );
            GL.Begin(PrimitiveType.Polygon);
            for (var i = 0; i < p.numverts; i++)
            {
                var v = p.verts[i];
                GL.TexCoord2(v[3], v[4]);
                GL.Vertex3(v);
            }
            GL.End( );

            lightMapTexture.BindLightmap((( GLTextureDesc )lightMapTexture.Desc).TextureNumber + lightMapNumber);
            GL.Enable(EnableCap.Blend);
            GL.Begin(PrimitiveType.Polygon);
            for (var i = 0; i < p.numverts; i++)
            {
                var v = p.verts[i];
                GL.TexCoord2(v[5], v[6]);
                GL.Vertex3(v);
            }
            GL.End( );

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);
        }
Exemple #4
0
        public override void DrawTexture2D(BaseTexture texture, RectangleF sourceRect, Rectangle destRect, Color?colour = null, bool hasAlpha = false)
        {
            if (hasAlpha)
            {
                GL.Disable(EnableCap.AlphaTest);
                GL.Enable(EnableCap.Blend);
            }

            GL.Enable(EnableCap.Texture2D);

            texture.Bind( );

            GL.Begin(PrimitiveType.Quads);

            if (colour.HasValue)
            {
                if (hasAlpha)
                {
                    GL.Color4(colour.Value);
                }
                else
                {
                    GL.Color3(colour.Value);
                }
            }
            else
            {
                if (hasAlpha)
                {
                    GL.Color4(1f, 1f, 1f, 1f);
                }
                else
                {
                    GL.Color3(1f, 1f, 1f);
                }
            }

            GL.TexCoord2(sourceRect.X, sourceRect.Y);
            GL.Vertex2(destRect.X, destRect.Y);
            GL.TexCoord2(sourceRect.X + sourceRect.Width, sourceRect.Y);
            GL.Vertex2(destRect.X + destRect.Width, destRect.Y);
            GL.TexCoord2(sourceRect.X + sourceRect.Width, sourceRect.Y + sourceRect.Height);
            GL.Vertex2(destRect.X + destRect.Width, destRect.Y + destRect.Height);
            GL.TexCoord2(sourceRect.X, sourceRect.Y + sourceRect.Height);
            GL.Vertex2(destRect.X, destRect.Y + destRect.Height);
            GL.End( );

            GL.Color3(1f, 1f, 1f);

            if (hasAlpha)
            {
                GL.Enable(EnableCap.AlphaTest);
                GL.Disable(EnableCap.Blend);
            }

            GL.Disable(EnableCap.Texture2D);
        }
Exemple #5
0
        public override void BeginParticles(BaseTexture texture)
        {
            base.BeginParticles(texture);

            texture.Bind( );

            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( int )TextureEnvMode.Modulate);
            GL.Begin(PrimitiveType.Triangles);
        }
Exemple #6
0
        /// <summary>
        /// Draw_TransPicTranslate
        /// Only used for the player color selection menu
        /// </summary>
        public override void DrawTransTranslate(BaseTexture texture, int x, int y, int width, int height, byte[] translation)
        {
            texture.Bind( );

            var c          = width * height;
            var destOffset = 0;
            var trans      = new uint[64 * 64];

            for (var v = 0; v < 64; v++, destOffset += 64)
            {
                var srcOffset = ((v * height) >> 6) * width;
                for (var u = 0; u < 64; u++)
                {
                    uint p = texture.Buffer.Data[srcOffset + ((u * width) >> 6)];
                    if (p == 255)
                    {
                        trans[destOffset + u] = p;
                    }
                    else
                    {
                        trans[destOffset + u] = this.Device.Palette.Table8to24[translation[p]];
                    }
                }
            }

            var handle = GCHandle.Alloc(trans, GCHandleType.Pinned);

            try
            {
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, 64, 64, 0,
                              PixelFormat.Rgba, PixelType.UnsignedByte, handle.AddrOfPinnedObject( ));
            }
            finally
            {
                handle.Free( );
            }

            this.Device.SetTextureFilters("GL_LINEAR");

            GL.Color3(1f, 1, 1);
            GL.Enable(EnableCap.Texture2D);
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0f, 0);
            GL.Vertex2(( float )x, y);
            GL.TexCoord2(1f, 0);
            GL.Vertex2(( float )x + width, y);
            GL.TexCoord2(1f, 1);
            GL.Vertex2(( float )x + width, y + height);
            GL.TexCoord2(0f, 1);
            GL.Vertex2(( float )x, y + height);
            GL.End( );
            GL.Disable(EnableCap.Texture2D);
        }
Exemple #7
0
        public override void DrawWaterPolyMultiTexture(byte[] lightMapData, BaseTexture texture, BaseTexture lightMapTexture, int lightMapTextureNumber, GLPoly p, double time)
        {
            GL.Enable(EnableCap.Texture2D);

            texture.Bind( );

            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( int )TextureEnvMode.Replace);

            this.Device.EnableMultitexture( );

            lightMapTexture.BindLightmap((( GLTextureDesc )lightMapTexture.Desc).TextureNumber + lightMapTextureNumber);
            var i = lightMapTextureNumber;

            if (lightMapTexture.LightMapModified[i])
            {
                lightMapTexture.CommitLightmap(lightMapData, i);
            }

            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( int )TextureEnvMode.Blend);
            GL.Begin(PrimitiveType.TriangleFan);

            var nv = new float[3];

            for (i = 0; i < p.numverts; i++)
            {
                var v = p.verts[i];
                GL.MultiTexCoord2(TextureUnit.Texture0, v[3], v[4]);
                GL.MultiTexCoord2(TextureUnit.Texture1, v[5], v[6]);

                nv[0] = ( float )(v[0] + 8 * Math.Sin(v[1] * 0.05 + time) * Math.Sin(v[2] * 0.05 + time));
                nv[1] = ( float )(v[1] + 8 * Math.Sin(v[0] * 0.05 + time) * Math.Sin(v[2] * 0.05 + time));
                nv[2] = v[2];

                GL.Vertex3(nv);
            }
            GL.End( );

            GL.Disable(EnableCap.Texture2D);
        }