-
Notifications
You must be signed in to change notification settings - Fork 5
2. Rendering Textures
Justin Skiles edited this page Apr 17, 2020
·
1 revision
-
Follow the steps from the above
Creating a Blank Windowexample. -
Add a
LoadContentmethod to yourMainGameclass. Update theMainGameconstructor to set the engine'sLoadContentaction to your method. This will inject your implementation into the game loop.private IWindow window; private IRenderer renderer; private Texture texture; public MainGame(IGameEngine engine) { this.engine = engine; engine.Initialize = () => Initialize(); engine.LoadContent = () => LoadContent(); } // Load a surface into memory from the image at your path. // Create a GPU-driven texture using a renderer and a surface. private void LoadContent() { Surface surface = new Surface("image.png", SurfaceType.PNG); texture = new Texture(renderer, surface); }
-
Add a
Drawmethod to yourMainGameclass. Update theMainGameconstructor to set the engine'sDrawaction to your method. This will inject your implementation into the game loop.private IRenderer renderer; private Texture texture; public MainGame(IGameEngine engine) { this.engine = engine; engine.Initialize = () => Initialize(); engine.LoadContent = () => LoadContent(); engine.Draw = (gameTime) => Draw(gameTime); } // Clear the screen to prevent stale renders. // Draw the texture at (100, 100). // Commit renders to the window. private void Draw(GameTime gameTime) { renderer.ClearScreen(); texture.Draw(100, 100); renderer.RenderPresent(); }
-
Add an
UnloadContentmethod to yourMainGameclass. Update theMainGameconstructor to set the engine'sUnloadContentaction to your method. This will inject your implementation into the game loop.private Texture texture; public MainGame(IGameEngine engine) { this.engine = engine; engine.Initialize = () => Initialize(); engine.LoadContent = () => LoadContent(); engine.Draw = (gameTime) => Draw(gameTime); engine.UnloadContent = () => UnloadContent(gameTime); } // Always dispose your assets! private void UnloadContent() { texture.Dispose(); }
-
Build and run to see drawn textures
dotnet builddotnet run
Check the Examples folder for runnable projects.