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(); }
public void SetPalette() { Sdl.SDL_Color[] colors = new Sdl.SDL_Color[255]; for(byte i=0;i<=254;i++) { colors[i].r=i; colors[i].g=i; colors[i].b=i; } IntPtr surfacePtr = VideoSetup(); int resultSetPalette = Sdl.SDL_SetPalette(surfacePtr, Sdl.SDL_LOGPAL|Sdl.SDL_PHYSPAL, colors, 0, 255); Assert.AreEqual(resultSetPalette, 0); Sdl.SDL_FreeSurface(surfacePtr); }
public override void DrawText(GridCoord point, int size, string text, System.Drawing.Color colour) { // Convert the colour Sdl.SDL_Color sdlcolour = new Sdl.SDL_Color(colour.R, colour.G, colour.B, colour.A); // Render the text to a surface IntPtr renderPtr = SdlTtf.TTF_RenderText_Solid(m_mainfont, text, sdlcolour); Sdl.SDL_Surface fontSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(renderPtr, typeof(Sdl.SDL_Surface)); // Calculate visibility WindowCoord wpoint = GridToWindowCoords(point); GridCoord toprightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y)); GridCoord bottomrightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y + fontSurface.h)); GridCoord bottomleftpoint = WindowToGridCoords(new WindowCoord(wpoint.X, wpoint.Y + fontSurface.h)); if (IsVisible(point,toprightpoint,bottomrightpoint,bottomleftpoint)) { // Then blit this to the main window Sdl.SDL_Rect fontRect = new Sdl.SDL_Rect(0, 0, (short)fontSurface.w, (short)fontSurface.h); Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)wpoint.X,(short)wpoint.Y,(short)fontSurface.w,(short)fontSurface.h); Sdl.SDL_BlitSurface(renderPtr, ref fontRect, m_surface, ref dstRect); } // Clean up the mess Sdl.SDL_FreeSurface(renderPtr); }
public static void CambiarColorTexto(byte r, byte g, byte b) { color = new Sdl.SDL_Color(r,g,b); }
public static void EscribirTexto(string texto, int x, int y) { if(Object.ReferenceEquals(color, null)) { color = new Sdl.SDL_Color(255, 255, 255); } IntPtr textoComoImagen = SdlTtf.TTF_RenderText_Solid(fuente.ApuntadorFuente, texto, color); if(textoComoImagen == IntPtr.Zero) { Console.WriteLine("Error al renderizar '{0}'", texto); } Sdl.SDL_Rect destino = new Sdl.SDL_Rect((short)x,(short)y,Ancho , Alto); Sdl.SDL_BlitSurface(textoComoImagen, ref origen, pantalla, ref destino); }
public static void EscribirTextoOculta(string texto, short x, short y, byte r, byte g, byte b, IntPtr fuente) { if ((texto == "") || (texto == null)) return; Sdl.SDL_Color color = new Sdl.SDL_Color(r, g, b); IntPtr textoComoImagen = SdlTtf.TTF_RenderText_Solid( fuente, texto, color); if (textoComoImagen == IntPtr.Zero) Environment.Exit(5); Sdl.SDL_Rect origen = new Sdl.SDL_Rect(0,0,ancho,alto); Sdl.SDL_Rect dest = new Sdl.SDL_Rect(x,y,ancho,alto); Sdl.SDL_BlitSurface(textoComoImagen, ref origen, pantallaOculta, ref dest); Sdl.SDL_FreeSurface(textoComoImagen); }
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; }
static void DrawText(IntPtr fontToDraw, string text, Vector2 position, Color color) { Sdl.SDL_Surface textImage; //The surface to be rendered on IntPtr textPointer; //Points to image data Sdl.SDL_Color foreColor = new Sdl.SDL_Color(color.R, color.G, color.B, color.A); //Convert Drawing.Color to Sdl color Sdl.SDL_Rect source; //Where to grab from Sdl.SDL_Rect target; //Where to display to textPointer = SdlTtf.TTF_RenderText_Blended(fontToDraw, text, foreColor); //Render text onto surface textImage = (Sdl.SDL_Surface)Marshal.PtrToStructure(textPointer, typeof(Sdl.SDL_Surface)); //Put the image data in its place source.w = target.w = (short)textImage.w; //Get width of image source.h = target.h = (short)textImage.h; //Get height of image source.x = 0; //Get all the image source.y = 0; //Get all the image target.x = (short)position.X; //Draw at given x target.y = (short)position.Y; //and given y Sdl.SDL_BlitSurface(textPointer, ref source, screen, ref target); //Draw text on screen Sdl.SDL_FreeSurface(textPointer); //Free the text image }