CGS Basics
In this tutorial, you will learn how to get started with the Cosmos Graphic Subsystem, CGS from here on.
Note
Some features may not be in the userkit, but as more userkits are released, more features will become more available. If you choose to download the developer kit however, you’ll have the bleeding edge version of Cosmos. This is also a tutorial for a C# kernel, so be aware of that. Cosmos is made in C#, but you can use other .NET languages, but for these purposes, C# will be used.
Steps
- First, put
Canvas canvas;
in the main kernel classpublic class Kernel : Sys.Kernel
.
using System;
using Sys = Cosmos.System;
using Cosmos.System.Graphics;
namespace GraphicTest
{
public class Kernel : Sys.Kernel
{
Canvas canvas;
protected override void BeforeRun()
{
- In a public void, type in
canvas = FullScreenCanvas.GetFullScreenCanvas();
Note that it can be called from any public methods, but the main BeforeRun method is used in this example.
In the same public void, type incanvas.Clear(Color.Blue);
. You can also replace the color with anything you want.
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");
canvas = FullScreenCanvas.GetFullScreenCanvas();
canvas.Clear(Color.Blue);
}
protected override void Run()
{
- In the same methods, or after the canvas has been initialized, you can start playing around with methods inside of the CGS. Here’s a working example you can use of CGS. Make a new operating system and replace your Kernel.cs with the following code:
using System;
using Sys = Cosmos.System;
using Cosmos.System.Graphics;
namespace GraphicTest
{
public class Kernel : Sys.Kernel
{
Canvas canvas;
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");
canvas = FullScreenCanvas.GetFullScreenCanvas();
canvas.Clear(Color.Blue);
}
protected override void Run()
{
try
{
Pen pen = new Pen(Color.Red);
canvas.DrawPoint(pen, 69, 69);
pen.Color = Color.GreenYellow;
canvas.DrawLine(pen, 250, 100, 400, 100);
pen.Color = Color.IndianRed;
canvas.DrawLine(pen, 350, 150, 350, 250);
pen.Color = Color.MintCream;
canvas.DrawLine(pen, 250, 150, 400, 250);
pen.Color = Color.PaleVioletRed;
canvas.DrawRectangle(pen, 350, 350, 80, 60);
Console.ReadKey();
canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32);
pen.Color = Color.LimeGreen;
canvas.DrawRectangle(pen, 450, 450, 80, 60);
Console.ReadKey();
Stop();
}
catch (Exception e)
{
mDebugger.Send("Exception occurred: " + e.Message);
mDebugger.Send(e.Message);
Stop();
}
}
}
}
Happy creating!