public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exBlitTextures.DrawScene : Event from SDLRenderer.DrawScene" ); var tW = texture.Width; var tH = texture.Height; var rect = new SDL.SDL_Rect(0, 0, tW, tH); for (int i = 0; i < ITTERATIONS; i++) { // Adjust color modulation var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); texture.ColorMod = c; // Blit the Texture now rect.x = random.Next(SDL_WINDOW_WIDTH - tW); rect.y = random.Next(SDL_WINDOW_HEIGHT - tH); renderer.Blit(rect, texture); } }
public static void UpdateRenderer(SDLRenderer renderer) { foreach (var example in _examples) { example.Renderer = renderer; } }
void ShutdownRenderer() { // (I thought this was about SDLRenderer, not the example form!) // Example Form change state, ignore the next couple lines and the comment above CalculateWindowSize(true); buttonInit.Text = "Init"; timer.Stop(); // Tell the examples the renderer is invalid SDLExampleSet.UpdateRenderer(null); // Tell SDLRenderer to stop it's thread. We do this so we don't destroy resources // being used before destroying the renderer itself. if (sdlRenderer != null) { sdlRenderer.DestroyWindow(); } // While SDL2ThingLayer implements IDisposable in all it's classes and // explicitly disposes of their resources in their destructors, I always // like to clean up after myself (old habits). ReleaseAssets(); // Dispose of the Renderer if (sdlRenderer != null) { sdlRenderer.Dispose(); } // This is all you really need to do though, GC will handle the rest surface = null; texture = null; font = null; sdlRenderer = null; }
// void SDLRenderer.Client_Delegate_WindowClosed( SDLRenderer renderer ); // // NOTE: This will be invoked asyncronously in the example forms thread (the // thread the SDLRenderer was created in) when the SDL_Window has been closed // by the user clicking the close window button. // // NOTE 2: This event only occurs and can only be registered for when creating // the SDLRenderer as a stand-alone SDL_Window. See: SetupRenderer() void SDLWindowClosed(SDLRenderer renderer) { Console.WriteLine("SDLWindowClosed : Event from SDLRenderer.EventDispatcher"); // User closed the SDL_Window ShutdownRenderer(); }
void BlitAsSprite(SDLRenderer renderer, SDLRenderer.Texture texture, double angle, Color c) { var pos = spinCentre.Add(RotateAround(spinDistance, angle)); var rect = new SDL.SDL_Rect(spriteRect.x + pos.x, spriteRect.y + pos.y, spriteRect.w, spriteRect.h); texture.ColorMod = c; renderer.Blit(rect, texture); }
internal Window(string title, int width, int height) { Helper.Init(); Title = title; Width = width; Height = height; window = new SDLWindow(title, width, height); renderer = new SDLRenderer(window); }
void ConsoleDump(SDLRenderer renderer) { // Dump some renderer info to the console Console.WriteLine( string.Format( "SDLRenderer:\n\tResolution = {0}x{1} {2}bpp\n\tPixelFormat = 0x{3}\n\tAlpha Mask = 0x{4}\n\tRed Mask = 0x{5}\n\tGreen Mask = 0x{6}\n\tBlue Mask = 0x{7}", renderer.WindowSize.Width, renderer.WindowSize.Height, renderer.BitsPerPixel, renderer.PixelFormat.ToString("X"), renderer.AlphaMask.ToString("X"), renderer.RedMask.ToString("X"), renderer.GreenMask.ToString("X"), renderer.BlueMask.ToString("X") )); // Dump some surface info to the console Console.WriteLine( string.Format( "Surface:\n\tResolution = {0}x{1} {2}bpp\n\tPixelFormat = 0x{3}\n\tAlpha Mask = 0x{4}\n\tRed Mask = 0x{5}\n\tGreen Mask = 0x{6}\n\tBlue Mask = 0x{7}", surface.Width, surface.Height, surface.BitsPerPixel, surface.PixelFormat.ToString("X"), surface.AlphaMask.ToString("X"), surface.RedMask.ToString("X"), surface.GreenMask.ToString("X"), surface.BlueMask.ToString("X") )); // Dump some texture info to the console Console.WriteLine( string.Format( "Texture:\n\tResolution = {0}x{1} {2}bpp\n\tPixelFormat = 0x{3}\n\tAlpha Mask = 0x{4}\n\tRed Mask = 0x{5}\n\tGreen Mask = 0x{6}\n\tBlue Mask = 0x{7}", texture.Width, texture.Height, texture.BitsPerPixel, texture.PixelFormat.ToString("X"), texture.AlphaMask.ToString("X"), texture.RedMask.ToString("X"), texture.GreenMask.ToString("X"), texture.BlueMask.ToString("X") )); // Dump some texture info to the console var fontMetrics = font.Metrics; Console.WriteLine( string.Format( "Font:\n\tHeight = {0}\n\tAscent = {1}\n\tDescent = {2}\n\tLineSkip = {3}", fontMetrics.Height, fontMetrics.Ascent, fontMetrics.Descent, fontMetrics.LineSkip )); }
// NOTE: This callback will be run in the SDLRenderer thread. // // Access to global resources should use the appropriate safe-guards for a // multi-threaded envirionment. // void SDLRenderer.Client_Delegate_RendererReset( SDLRenderer renderer ); void SDLRendererReset(SDLRenderer renderer) { // The underlying SDL_Window and/or SDL_Renderer changed, we need to // recreate our assets ReleaseAssets(); CreateAssetsForRenderer(renderer); // Tell all the example scenes to recreate their assets SDLExampleSet.RendererReset(renderer); }
public static void RendererReset(SDLRenderer renderer) { foreach (var example in _examples) { if (example.Enabled) { example.RendererReset(renderer); } } }
void CreateAssetsFor(SDLRenderer renderer) { // Get the size of the message textSize = font.TextSize(TEXT); // Create a Surface for the message var surface = font.TextBlended(TEXT, Color.White); // Turn the surface into a Texture textTure = renderer.CreateTextureFromSurface(surface); }
public SDLTexture RenderGlyph_Solid_Texture(char Ch, SDL.SDL_Color Fg, SDLRenderer Renderer) { IntPtr Result = SDL_ttf.TTF_RenderGlyph_Solid(myPtr, Ch, Fg); try { return(new SDLTexture(SDL.SDL_CreateTextureFromSurface(Renderer.Ptr, Result))); } finally { SDL.SDL_FreeSurface(Result); } }
//Texture public SDLTexture RenderText_Blended_Texture(string Text, SDL.SDL_Color Fg, SDLRenderer Renderer) { IntPtr Result = SDL_ttf.TTF_RenderText_Blended(myPtr, Text, Fg); try { return(new SDLTexture(SDL.SDL_CreateTextureFromSurface(Renderer.Ptr, Result))); } finally { SDL.SDL_FreeSurface(Result); } }
void SetupRenderer() { // Example form changes, ignore the next few lines CalculateWindowSize(); buttonInit.Text = "Denit"; // Get anchoring from example form checkbox var anchor = checkAnchored.Checked; // Create the renderer if (anchor) { // Create the SDLRenderer as an anchored window to the gamePanel. sdlRenderer = new SDLRenderer(this, gamePanel); } else { // Create the SDLRenderer as a stand-alone SDL_Window with the WS_EX_TOOLWINDOW extended style. sdlRenderer = new SDLRenderer(this, SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, "SDL_Window as a tool window in it's own thread!", SDLWindowClosed); } // Add some event callbacks, this example just reports the event ID to console sdlRenderer.KeyDown += EventReporter; sdlRenderer.KeyUp += EventReporter; sdlRenderer.MouseButtonDown += EventReporter; sdlRenderer.MouseButtonUp += EventReporter; sdlRenderer.MouseMove += EventReporter; sdlRenderer.MouseWheel += EventReporter; // We have assets, we need to handle changes to the SDL_Window and SDL_Renderer sdlRenderer.RendererReset += SDLRendererReset; // Setting certain render states must be done from the SDL thread. // To execute something in the SDL thread, use SDLRenderer.Invoke() // or SDLRenderer.BeginInvoke() as appropriate. // // NOTE: SDLRenderer.[Begin]Invoke() is not performing a standard // Invoke(). What is happening is a user event is being pushed onto // the SDL_Event queue to invoke the delegate. This will cause the // actual execution of the method to be delayed. As a result Invoke() // will block the calling thread until the event is handled. If you // want a non-blocking async invocation use SDLRenderer.BeginInvoke() // instead. sdlRenderer.Invoke(InitInThread); // Start the performance feedback timer (more example form stuff) timer.Start(); }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawPoints2.DrawScene : Event from SDLRenderer.DrawScene" ); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); renderer.DrawPoints(_screenMap, TOTAL_PIX, c); }
void InitInThread(SDLRenderer renderer) { // Set the render blender mode renderer.BlendMode = SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND; // Load some assets CreateAssetsForRenderer(renderer); // Tell the examples the renderer to use SDLExampleSet.UpdateRenderer(sdlRenderer); // Barf to the console ConsoleDump(renderer); }
public IntPtr RenderGlyph_Solid_TexturePtr(char Ch, SDL.SDL_Color Fg, SDLRenderer Renderer) { IntPtr Result = SDL_ttf.TTF_RenderGlyph_Solid(myPtr, Ch, Fg); Util.ThrowIfPointerZero(Result); try { return(SDL.SDL_CreateTextureFromSurface(Renderer.Ptr, Result)); } finally { SDL.SDL_FreeSurface(Result); } }
public IntPtr RenderUTF8_Blended_TexturePtr(string Text, SDL.SDL_Color Fg, SDLRenderer Renderer) { IntPtr Result = SDL_ttf.TTF_RenderUTF8_Blended(myPtr, Text, Fg); Util.ThrowIfPointerZero(Result); try { return(new SDLTexture(SDL.SDL_CreateTextureFromSurface(Renderer.Ptr, Result))); } finally { SDL.SDL_FreeSurface(Result); } }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawFilledCircles.DrawScene : Event from SDLRenderer.DrawScene" ); for (int i = 0; i < ITTERATIONS; i++) { var x = random.Next(SDL_WINDOW_WIDTH); var y = random.Next(SDL_WINDOW_HEIGHT); var r = random.Next(SDL_WINDOW_WIDTH / 10); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); renderer.DrawFilledCircle(x, y, r, c); } }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawRects.DrawScene : Event from SDLRenderer.DrawScene" ); for (int i = 0; i < ITTERATIONS; i++) { var x1 = random.Next(SDL_WINDOW_WIDTH); var y1 = random.Next(SDL_WINDOW_HEIGHT); var x2 = random.Next(SDL_WINDOW_WIDTH); var y2 = random.Next(SDL_WINDOW_HEIGHT); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); renderer.DrawRect(x1, y1, x2, y2, c); } }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawPoints.DrawScene : Event from SDLRenderer.DrawScene" ); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); for (int y = 0; y < SDL_WINDOW_HEIGHT; y++) { for (int x = 0; x < SDL_WINDOW_WIDTH; x++) { renderer.DrawPoint(x, y, c); } } }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawText.DrawScene : Event from SDLRenderer.DrawScene" ); var size = font.TextSize(TEXT); for (int i = 0; i < ITTERATIONS; i++) { var p = new SDL.SDL_Point( random.Next(SDL_WINDOW_WIDTH - size.Width), random.Next(SDL_WINDOW_HEIGHT - size.Height) ); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); renderer.DrawText(p, font, TEXT, c); } }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exDrawText2.DrawScene : Event from SDLRenderer.DrawScene" ); for (int i = 0; i < ITTERATIONS; i++) { var rect = new SDL.SDL_Rect( random.Next(SDL_WINDOW_WIDTH - textSize.Width), random.Next(SDL_WINDOW_HEIGHT - textSize.Height), textSize.Width, textSize.Height ); var c = Color.FromArgb( random.Next(256), random.Next(256), random.Next(256), random.Next(256) ); textTure.ColorMod = c; renderer.Blit(rect, textTure); } }
public SDLExampleSceneRender(Form form, string optOn, string optOff = null) { if (form == null) { throw new ArgumentNullException("form", "Cannot be null!"); } if (string.IsNullOrEmpty(optOn)) { throw new ArgumentNullException("optOn", "Cannot be null!"); } _form = form; _optOn = optOn; _optOff = string.IsNullOrEmpty(optOff) ? optOn : optOff; _enabled = false; _renderer = null; _button = new Button(); _button.Text = optOn; _button.CalculcateControlSizeAndLocation(BASE_ELEMENTS + SDLExampleSet.Count); _button.Click += ButtonClick; form.Controls.Add(_button); }
void CreateAssetsForRenderer(SDLRenderer renderer) { // Load Surface from a file // // NOTE: Surfaces are deprecated and require conversion to Textures before blitting. surface = renderer.LoadSurface("pointsprite.png"); // Set the blend mode for surface blitting surface.BlendMode = SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND; // Create a Texture from the Surface. // // No need to set the blend mode, etc - all rendering information is copied // directly in SDLRenderer.CreateTextureFromSurface() from the Surface settings. texture = renderer.CreateTextureFromSurface(surface); // Load a font from file. font = renderer.CreateFont(12, "LibertySans.ttf"); if (font == null) { throw new Exception(string.Format("Unable to create font!\n\n{0}", SDL.SDL_GetError())); } }
public static IntPtr LoadTexturePtr(SDLRenderer Renderer, string File) { return(SDL_image.IMG_LoadTexture(Renderer.Ptr, File)); }
public override void DrawScene(SDLRenderer renderer) { // You don't really want to uncomment the next line... // Console.WriteLine( "exSample1.DrawScene : Event from SDLRenderer.DrawScene" ); if (true) { // Draw a couple solid lines over the window var p1 = new SDL.SDL_Point(SDL_WINDOW_WIDTH / 2, 0); var p2 = new SDL.SDL_Point(SDL_WINDOW_WIDTH / 2, SDL_WINDOW_HEIGHT); var p3 = new SDL.SDL_Point(0, SDL_WINDOW_HEIGHT / 2); var p4 = new SDL.SDL_Point(SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT / 2); var c = Color.White; renderer.DrawLine(p1, p2, c); renderer.DrawLine(p3, p4, c); } if (true) { // Draw a blue rect var rect1 = new SDL.SDL_Rect(32, 32, 64, 64); var c = Color.FromArgb(255, 0, 128, 128); renderer.DrawFilledRect(rect1, c); // Draw a translucent red rect var rect2 = new SDL.SDL_Rect(rect1.x + 32, rect1.y + 32, rect1.w, rect1.h); c = Color.FromArgb(128, 255, 0, 0); renderer.DrawFilledRect(rect2, c); // Outline it c = Color.FromArgb(255, 255, 0, 0); renderer.DrawRect(rect2, c); // Draw a couple translucent lines over the rects var p1 = new SDL.SDL_Point(rect1.x, rect1.x); var p2 = new SDL.SDL_Point(p1.x + 64, p1.y + 64); var p3 = new SDL.SDL_Point(p1.x + 32, p1.y + 64); var p4 = new SDL.SDL_Point(p1.x + 64, p1.y + 32); c = Color.FromArgb(128, 255, 255, 255); renderer.DrawLine(p1, p2, c); renderer.DrawLine(p3, p4, c); } if (true) { // Draw a yellow circle var p1 = new SDL.SDL_Point(192, 64); var c = Color.Yellow; renderer.DrawFilledCircle(p1, 32, c); // Draw a magenta circle var p2 = new SDL.SDL_Point(p1.x + 32, p1.y + 32); c = Color.FromArgb(128, 255, 0, 255); renderer.DrawFilledCircle(p2, 32, c); // Outline it c = Color.FromArgb(255, 255, 0, 255); renderer.DrawCircle(p2, 32, c); } if (true) { var c = Color.White; // Blit the surface var rect1 = new SDL.SDL_Rect(32, 192, surface.Width, surface.Height); surface.ColorMod = c; renderer.Blit(rect1, surface); // Blit the texture var rect2 = new SDL.SDL_Rect(rect1.x + surface.Width / 4, rect1.y + surface.Height / 4, rect1.w, rect1.h); texture.ColorMod = c; renderer.Blit(rect2, texture); } if (true) { // Don't do scene control in DrawScene, this is just an example spinAngle += spinStep; if (spinAngle > 360.0) { spinAngle -= 360.0; } // Orbit var c = Color.FromArgb(255, 64, 64, 64); renderer.DrawCircle(spinCentre, (int)spinDistance, c); // Blit the surface as a sprite BlitAsSprite(renderer, surface, spinAngle, surfaceColor); // Blit the texture as a sprite BlitAsSprite(renderer, texture, -spinAngle, textureColor); } if (true) { // Draw some text const string text = "They're Pinky and the Brain!"; // Solid White Bold var c = Color.White; var p = new SDL.SDL_Point(32, 384); renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_BOLD); // Alpha Red Italic c = Color.FromArgb(128, 255, 0, 0); p.y += 16; renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_ITALIC); // Solid Green Strike-Through c = Color.FromArgb(255, 0, 255, 0); p.y += 16; renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_STRIKETHROUGH); // Alpha Blue Underline c = Color.FromArgb(128, 0, 0, 255); p.y += 16; renderer.DrawText(p, font, text, c, SDL_ttf.TTF_STYLE_UNDERLINE); } }
// NOTE: These callbacks will be run in the SDLRenderer thread. // // Access to global resources should use the appropriate safe-guards for a // multi-threaded envirionment. // void SDLRenderer.Client_Delegate_SDL_Event( SDLRenderer renderer, SDL.SDL_Event e ) void EventReporter(SDLRenderer renderer, SDL.SDL_Event e) { var str = string.Format("EventReporter : Event from SDLRenderer.EventDispatcher: 0x{0}", e.type.ToString("X")); Console.WriteLine(str); }
public static SDLTexture LoadTexture(SDLRenderer Renderer, string File) { return(new SDLTexture(SDL_image.IMG_LoadTexture(Renderer.Ptr, File))); }
public static IntPtr LoadTexture_RWPtr(SDLRenderer Renderer, IntPtr Src, bool Freesrc) { return(SDL_image.IMG_LoadTexture_RW(Renderer.Ptr, Src, Convert.ToInt32(Freesrc))); }
public static SDLTexture LoadTextureTyped_RW(SDLRenderer Renderer, IntPtr Src, bool Freesrc, string Type) { return(new SDLTexture(SDL_image.IMG_LoadTextureTyped_RW(Renderer.Ptr, Src, Convert.ToInt32(Freesrc), Type))); }