Example #1
0
        public void RenderGlyph_Blended()
        {
            this.Quit();
            this.Init();
            IntPtr surfacePtr = VideoSetup();

            Sdl.SDL_Rect rect1   = new Sdl.SDL_Rect(0, 0, 400, 400);
            Sdl.SDL_Rect rect2   = new Sdl.SDL_Rect(0, 0, 400, 400);
            IntPtr       fontPtr = SdlTtf.TTF_OpenFont("../../FreeSans.ttf", 12);

            Sdl.SDL_Color colorfg        = new Sdl.SDL_Color(254, 0, 0);
            IntPtr        fontSurfacePtr = SdlTtf.TTF_RenderGlyph_Blended(fontPtr, 1000, colorfg);

            Assert.IsFalse(fontSurfacePtr == IntPtr.Zero);
            int result = Sdl.SDL_BlitSurface(fontSurfacePtr, ref rect1, surfacePtr, ref rect2);

            Assert.AreEqual(result, 0);
            Sdl.SDL_UpdateRect(surfacePtr, 0, 0, 400, 400);
            Thread.Sleep(sleepTime);
            this.Quit();
        }
Example #2
0
        private SDLGlyph CreateGlyph(char Char)
        {
            Sdl.SDL_Surface initial;
            Sdl.SDL_Surface intermediary;

            //Sdl.SDL_Rect rect;
            int w, h;

            int[] texture = new int[1];

            Sdl.SDL_Color color = new Sdl.SDL_Color(255, 255, 255, 255);
            /* Use SDL_TTF to render our text */
            //IntPtr Test = SdlTtf.TTF_RenderGlyph_Shaded(m_Font, (short)Char, color, new Sdl.SDL_Color(0, 0, 0, 0));
            IntPtr Test = SdlTtf.TTF_RenderGlyph_Blended(m_Font, (short)Char, color);

            //initial = test;
            initial = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(Test, typeof(Sdl.SDL_Surface));

            /* Convert the rendered text to a known format */
            w = nextpoweroftwo(initial.w);
            h = nextpoweroftwo(initial.h);

            IntPtr Temp = Sdl.SDL_CreateRGBSurface(Sdl.SDL_SRCALPHA, w, h, 32,
                                                   0, 0, 0, 0);

            intermediary = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(Temp, typeof(Sdl.SDL_Surface));

            Sdl.SDL_SetAlpha(Temp, Sdl.SDL_SRCALPHA, 255);


            //Sdl.SDL_PixelFormat;
            Sdl.SDL_BlitSurface(Test, ref initial.clip_rect, Temp, ref intermediary.clip_rect);

            /* Tell GL about our new texture */
            Gl.glGenTextures(1, texture);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[0]);

            if (!MipMap)
            {
                Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 4, w, h, 0, Gl.GL_BGRA,
                                Gl.GL_UNSIGNED_BYTE, intermediary.pixels);

                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_ENV, Gl.GL_MODULATE);
            }
            else
            {
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_NEAREST);
                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGB8, w, h, Gl.GL_ABGR_EXT, Gl.GL_UNSIGNED_BYTE, intermediary.pixels);
            }

            /*int[] ExtraTex = new int[1];
             * Gl.glGenTextures(1, ExtraTex);
             * Gl.glBindTexture(Gl.GL_TEXTURE_2D, ExtraTex[0]);
             *
             * Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 4, w, h, 0, Gl.GL_ABGR_EXT,
             *  Gl.GL_UNSIGNED_BYTE, intermediary.pixels);
             *
             * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
             * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
             * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_ENV, Gl.GL_MODULATE);//
             *
             *
             * /* Clean up */
            Sdl.SDL_FreeSurface(Temp);
            Sdl.SDL_FreeSurface(Test);
            //Gl.glDeleteTextures(1, texture);
            SDLMetrics Metrics = new SDLMetrics();


            SdlTtf.TTF_GlyphMetrics(m_Font, (short)Char, out Metrics.MinX, out Metrics.MaxX, out Metrics.MinY, out Metrics.MaxY, out Metrics.Advance);


            SDLGlyph ReturnGlyph = new SDLGlyph(Metrics, texture[0], w, h, Char);

            BuildList(ReturnGlyph);

            //ReturnGlyph.extraGLTex = ExtraTex[0];
            return(ReturnGlyph);
        }