Example #1
0
        public static void glfons__renderDraw(object userPtr, float[] verts, float[] tcoords,
                                              uint[] colors, int nverts)
        {
            GLFONScontext gl = (GLFONScontext)userPtr;

            if (gl.tex == 0)
            {
                return;
            }
            GL.BindTexture(TextureTarget.Texture2D, gl.tex);
            GL.Enable(EnableCap.Texture2D);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.ColorArray);

            //GL.VertexPointer(2, VertexPointerType.Float, sizeof(float)*2, verts);
            //GL.TexCoordPointer(2, TexCoordPointerType.Float, sizeof(float)*2, tcoords);
            //GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(uint), colors);

            GL.VertexPointer(2, VertexPointerType.Float, 0, verts);
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, tcoords);
            GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, colors);

            GL.DrawArrays(BeginMode.Triangles, 0, nverts);

            GL.Disable(EnableCap.Texture2D);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.DisableClientState(ArrayCap.ColorArray);
        }
Example #2
0
        public static void glfons__renderDelete(object userPtr)
        {
            GLFONScontext gl = (GLFONScontext)userPtr;

            if (gl.tex != 0)
            {
                GL.DeleteTextures(1, ref gl.tex);
            }
            gl.tex = 0;
            //free(gl);
        }
Example #3
0
        public static FONScontext glfonsCreate(int width, int height, FONSflags flags)
        {
            FONSparams    fparams;
            GLFONScontext gl = new GLFONScontext();

            fparams.width        = width;
            fparams.height       = height;
            fparams.flags        = flags;
            fparams.renderCreate = glfons__renderCreate;
            fparams.renderResize = glfons__renderResize;
            fparams.renderUpdate = glfons__renderUpdate;
            fparams.renderDraw   = glfons__renderDraw;
            fparams.renderDelete = glfons__renderDelete;
            fparams.userPtr      = gl;

            return(FontStash.fonsCreateInternal(ref fparams));
        }
Example #4
0
        public static void glfons__renderUpdate(object uptr, ref int[] rect, byte[] data)
        {
            GLFONScontext gl = (GLFONScontext)uptr;
            int           w  = rect[2] - rect[0];
            int           h  = rect[3] - rect[1];

            if (gl.tex == 0)
            {
                return;
            }
            GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit);
            GL.BindTexture(TextureTarget.Texture2D, gl.tex);
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
            GL.PixelStore(PixelStoreParameter.UnpackRowLength, gl.width);
            GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, rect[0]);
            GL.PixelStore(PixelStoreParameter.UnpackSkipRows, rect[1]);
            GL.TexSubImage2D(TextureTarget.Texture2D, 0, rect[0], rect[1], w, h,
                             PixelFormat.Alpha, PixelType.UnsignedByte, data);
            GL.PopClientAttrib();
        }
Example #5
0
        public static int glfons__renderCreate(object userPtr, int width, int height)
        {
            GLFONScontext gl = userPtr as GLFONScontext;

            // Create may be called multiple times, delete existing texture.
            if (gl.tex != 0)
            {
                GL.DeleteTextures(1, ref gl.tex);
                gl.tex = 0;
            }
            GL.GenTextures(1, out gl.tex);
            if (!(gl.tex != 0))
            {
                return(0);
            }
            gl.width  = width;
            gl.height = height;
            GL.BindTexture(TextureTarget.Texture2D, gl.tex);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha,
                          gl.width, gl.height, 0, PixelFormat.Alpha, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                            (int)TextureMinFilter.Linear);
            return(1);
        }