Пример #1
0
        private void DrawGlyph(SDLGlyph SGlyph, float X, float Y, Color4f Color)
        {
            Gl.glTranslatef(X, Y, 0.0f);
            Gl.glColor4f(Color.r, Color.g, Color.b, Color.a);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, SGlyph.GLTexture);
            //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
            Gl.glCallList(SGlyph.DispList);
            Gl.glTranslatef(-X, -Y, 0.0f);


            if (RenderBoundingBox)                  //Debug
            {
                Gl.glDisable(Gl.GL_TEXTURE_2D);
                Gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                Gl.glBegin(Gl.GL_LINE_STRIP);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glEnd();
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                //Gl.glColor4f((float)SrcColor.Color.R / 255.0f, (float)SrcColor.Color.G / 255.0f, (float)SrcColor.Color.B / 255.0f, (float)SrcColor.Color.A / 255.0f);
            }
        }
Пример #2
0
        private void BuildList(SDLGlyph SGlyph)
        {
            int NewList = Gl.glGenLists(1);

            Gl.glNewList(NewList, Gl.GL_COMPILE);
            Gl.glTranslatef(SGlyph.Metrics.MinX, SGlyph.Metrics.MaxY, 0.0f);
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glTexCoord2f(0, 0); Gl.glVertex3f(0.0f, 0.0f, 0);
            Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.0f + SGlyph.Width, 0.0f, 0);
            Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.0f + SGlyph.Width, 0.0f - SGlyph.Height, 0);
            Gl.glTexCoord2f(0, 1); Gl.glVertex3f(0.0f, 0.0f - SGlyph.Height, 0);
            Gl.glEnd();
            Gl.glTranslatef(-SGlyph.Metrics.MinX, -SGlyph.Metrics.MaxY, 0.0f);
            Gl.glEndList();

            SGlyph.DispList = NewList;
        }
Пример #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 void DrawGlyph(SDLGlyph SGlyph, float X, float Y, Color4f Color)
        {
            Gl.glTranslatef(X, Y, 0.0f);
            Gl.glColor4f(Color.r, Color.g, Color.b, Color.a);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, SGlyph.GLTexture);
            //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
            Gl.glCallList(SGlyph.DispList);
            Gl.glTranslatef(-X, -Y, 0.0f);

            if (RenderBoundingBox)                  //Debug
            {
                Gl.glDisable(Gl.GL_TEXTURE_2D);
                Gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                Gl.glBegin(Gl.GL_LINE_STRIP);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y, 0.0f);
                Gl.glVertex3f(X + SGlyph.Width, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y - SGlyph.Height, 0.0f);
                Gl.glVertex3f(X, Y, 0.0f);
                Gl.glEnd();
                Gl.glEnable(Gl.GL_TEXTURE_2D);
                //Gl.glColor4f((float)SrcColor.Color.R / 255.0f, (float)SrcColor.Color.G / 255.0f, (float)SrcColor.Color.B / 255.0f, (float)SrcColor.Color.A / 255.0f);
            }
        }
Пример #5
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;
        }
Пример #6
0
        private void BuildList(SDLGlyph SGlyph)
        {
            int NewList = Gl.glGenLists(1);

            Gl.glNewList(NewList, Gl.GL_COMPILE);
            Gl.glTranslatef(SGlyph.Metrics.MinX, SGlyph.Metrics.MaxY, 0.0f);
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glTexCoord2f(0, 0); Gl.glVertex3f(0.0f, 0.0f, 0);
            Gl.glTexCoord2f(1, 0); Gl.glVertex3f(0.0f + SGlyph.Width, 0.0f, 0);
            Gl.glTexCoord2f(1, 1); Gl.glVertex3f(0.0f + SGlyph.Width, 0.0f - SGlyph.Height, 0);
            Gl.glTexCoord2f(0, 1); Gl.glVertex3f(0.0f, 0.0f - SGlyph.Height, 0);
            Gl.glEnd();
            Gl.glTranslatef(-SGlyph.Metrics.MinX, -SGlyph.Metrics.MaxY, 0.0f);
            Gl.glEndList();

            SGlyph.DispList = NewList;
        }