Example #1
0
        public void draw(ref vect2d dst, ref vect2d src, ref vect2d dim)
        {
            // find texture coordinates
            float texX1 = (float)(src.x / w);
            float texY1 = (float)(src.y / h);
            float texX2 = (float)((src.x + dim.x) / w);
            float texY2 = (float)((src.y + dim.y) / h);

            // bind it
            GL.BindTexture(TextureTarget.Texture2D, tex_id);

            // draw it
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(texX1, texY1);
            GL.Vertex2((float)dst.x, (float)dst.y);

            GL.TexCoord2(texX2, texY1);
            GL.Vertex2((float)(dst.x + dim.x), (float)dst.y);

            GL.TexCoord2(texX2, texY2);
            GL.Vertex2((float)(dst.x + dim.x), (float)(dst.y + dim.y));

            GL.TexCoord2(texX1, texY2);
            GL.Vertex2((float)dst.x, (float)(dst.y + dim.y));
            GL.End();
        }
Example #2
0
        public void draw(ref vect2d dst)
        {
            // find texture coordinates
            float texX1 = 0;
            float texY1 = 0;
            float texX2 = 1;
            float texY2 = 1;

            // bind it
            GL.BindTexture(TextureTarget.Texture2D, tex_id);

            // draw it
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(texX1, texY1);
            GL.Vertex2((float)dst.x, (float)dst.y);

            GL.TexCoord2(texX2, texY1);
            GL.Vertex2((float)(dst.x + w), (float)dst.y);

            GL.TexCoord2(texX2, texY2);
            GL.Vertex2((float)(dst.x + w), (float)(dst.y + h));

            GL.TexCoord2(texX1, texY2);
            GL.Vertex2((float)dst.x, (float)(dst.y + h));
            GL.End();
        }
        public override vect3d sample(vect3d pos)
        {
            // find modulo value (texture wrapping)
            vect2d p = new vect2d((pos.x % 1) * bmp.Width, ((1 - pos.y) % 1) * bmp.Height);

            if (p.x < 0)
            {
                p.x += bmp.Width;
            }
            if (p.y < 0)
            {
                p.y += bmp.Height;
            }

            // get color out of bmp
            Color color = bmp.GetPixel((int)p.x, (int)p.y);

            return(new vect3d(color.R / 255.0, color.G / 255.0, color.B / 255.0));
        }
Example #4
0
        public override vect3d sample(vect3d pos)
        {
            // find modulo value (texture wrapping)
            vect2d p = new vect2d((pos.x % 1) * bmp.Width, ((1 - pos.y) % 1) * bmp.Height);

            if (p.x < 0)
            {
                p.x += bmp.Width;
            }
            if (p.y < 0)
            {
                p.y += bmp.Height;
            }

            // get color out of bmp
            int    i = (int)p.x, j = (int)p.y;
            int    ip = (i + 1) % bmp.Width, jp = (j + 1) % bmp.Height;
            double dx = p.x - i, dy = p.y - j;

            Color color;

            color = bmp.GetPixel(i, j);
            vect3d c00 = new vect3d(color.R, color.G, color.B);

            color = bmp.GetPixel(i, jp);
            vect3d c01 = new vect3d(color.R, color.G, color.B);

            color = bmp.GetPixel(ip, j);
            vect3d c10 = new vect3d(color.R, color.G, color.B);

            color = bmp.GetPixel(ip, jp);
            vect3d c11 = new vect3d(color.R, color.G, color.B);

            // combine samples with lerp
            return(((1 - dx) * (1 - dy) * c00 + (1 - dx) * dy * c01 + dx * (1 - dy) * c10 + dx * dy * c11) * (1.0 / 255.0));
        }