public SDLTexture RenderTextBlended(SDLRenderer renderer, string text, Color color) { // Check inputs. if (renderer == null) { throw new ArgumentNullException("renderer"); } // Convert color to SDL format. SDL.SDL_Color sdlColor = new SDL.SDL_Color(); sdlColor.r = color.RedByte; sdlColor.g = color.GreenByte; sdlColor.b = color.BlueByte; // Render the text message to an SDL_Surface and then convert the surface into an // SDL texture. SDLTexture texture; using (SDLSurface surface = new SDLSurface(SDL_ttf.TTF_RenderText_Blended( mFont, text, sdlColor))) { texture = new SDLTexture(renderer, surface); } return(texture); }
public void Draw(SDLTexture texture, int x, int y) { // Sanity check our inputs, make sure they are valid. if (texture == null) { throw new ArgumentNullException("texture"); } if (x < 0) { throw new ArgumentOutOfRangeException("x"); } else if (y < 0) { throw new ArgumentOutOfRangeException("y"); } // Set up the target rectangle, which is the area on the screen that this texture will // be drawn to. SDL.SDL_Rect target = new SDL.SDL_Rect(); target.x = x; target.y = y; target.w = texture.Width; target.h = texture.Height; // Set up the source rectangle, which is the area of the texture that will be drawn to // the screen. SDL.SDL_Rect source = new SDL.SDL_Rect(); source.x = 0; source.y = 0; source.w = texture.Width; source.h = texture.Height; // Now issue the draw command to SDL. SDL.SDL_RenderCopy(mRenderer, texture.TexturePtr, ref source, ref target); }
private static void RunGame() { // Create the main render window. SDLWindow window = new SDLWindow( "An SDL2 window", 100, 100, 800, 600 ); SDLRenderer renderer = new SDLRenderer( window ); // Load a test image. SDLTexture texture = new SDLTexture( renderer, "hello.bmp" ); SDLFont font = new SDLFont( renderer, "hello.ttf", 24 ); SDLTexture textTexture = font.RenderTextBlended( renderer, "Hello World!!", Color.BlueColor ); // Event loop. SDL.SDL_Event eventInfo = new SDL.SDL_Event(); bool shouldQuit = false; while ( !shouldQuit ) { CheckForSDLErrors(); // Pump and process pending OS events. while ( SDL.SDL_PollEvent( out eventInfo ) != 0 ) { if ( eventInfo.type == SDL.SDL_EventType.SDL_QUIT ) { shouldQuit = true; } } // Render all of our stuffs. renderer.Clear(); renderer.Draw( texture, 32, 32 ); renderer.Draw( textTexture, 0, 400 ); renderer.Present(); } }
public void Draw( SDLTexture texture, int x, int y ) { // Sanity check our inputs, make sure they are valid. if ( texture == null ) { throw new ArgumentNullException( "texture" ); } if ( x < 0 ) { throw new ArgumentOutOfRangeException( "x" ); } else if ( y < 0 ) { throw new ArgumentOutOfRangeException( "y" ); } // Set up the target rectangle, which is the area on the screen that this texture will // be drawn to. SDL.SDL_Rect target = new SDL.SDL_Rect(); target.x = x; target.y = y; target.w = texture.Width; target.h = texture.Height; // Set up the source rectangle, which is the area of the texture that will be drawn to // the screen. SDL.SDL_Rect source = new SDL.SDL_Rect(); source.x = 0; source.y = 0; source.w = texture.Width; source.h = texture.Height; // Now issue the draw command to SDL. SDL.SDL_RenderCopy( mRenderer, texture.TexturePtr, ref source, ref target ); }
public SDLTexture RenderTextBlended( SDLRenderer renderer, string text, Color color ) { // Check inputs. if ( renderer == null ) { throw new ArgumentNullException( "renderer" ); } // Convert color to SDL format. SDL.SDL_Color sdlColor = new SDL.SDL_Color(); sdlColor.r = color.RedByte; sdlColor.g = color.GreenByte; sdlColor.b = color.BlueByte; // Render the text message to an SDL_Surface and then convert the surface into an // SDL texture. SDLTexture texture; using ( SDLSurface surface = new SDLSurface( SDL_ttf.TTF_RenderText_Blended( mFont, text, sdlColor ) ) ) { texture = new SDLTexture( renderer, surface ); } return texture; }