Пример #1
0
 public SDLGlyph(SDLMetrics Metrics, int GLTexture, int Width, int Height, char Char)
 {
     this.Metrics   = Metrics;
     this.GLTexture = GLTexture;
     this.Width     = Width;
     this.Height    = Height;
     this.Char      = Char;
 }
Пример #2
0
 public SDLGlyph(SDLMetrics Metrics, int GLTexture, int Width, int Height, char Char)
 {
     this.Metrics = Metrics;
     this.GLTexture = GLTexture;
     this.Width = Width;
     this.Height = Height;
     this.Char = Char;
 }
Пример #3
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);
        }
Пример #4
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;
        }