Skip to the content.

OpenTK3DEngine

Todo:

Table of Contents

Overview

This library simplifies the use of the openTK library by wrapping it into simple to use functions, perferct for C# and VB simple game development.

Using the library:

  1. Add the library to your solution from Nuget.

Example code:

  1. Add a new .cs line to your console app, that will be your main place to code
    (Example bellow no. 1)
  2. On your program.cs file add the example code no. 2,
  3. If you dont want the console opening change your project properties to Windows Application
using System;
using OpenTK;
using OpenTK.Graphics;
using Program;

namespace yourNameSpace
{
    public class yourClass : MainRenderWindow
    {
        public Game(int width, int height, string title, double fps) : base(width, height, title, fps)
        {
        }

        protected override void OnLoad()
        {
            setClearColor(new Color4(0.0f, 0.0f, 0.0f, 1.0f)); //Sets Background Color
            UseDepthTest = false; //Enables Depth Testing for 3D
            UseAlpha = true; //Enables alpha use
            KeyboardAndMouseInput = false; //Enables keyboard and mouse input for 3D movement
            base.OnLoad();
        }

        protected override void OnRenderFrame(FrameEventArgs e)
        {
            Clear();

            DrawEllipse(500, 500, 10f, 10f, new Color4(1.0f, 1.0f, 1.0f, 1.0f)); //Draws a circle

            base.OnRenderFrame(e);
        }

        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);
        }
    }
}
namespace yourNamespace
{
    static class Program
    {
        static void Main(string[] args)
        {
            using youClass game = new youClass(1000, 1000, "Test App", 60.0);
            //Run takes a double, which is how many frames per second it should strive to reach.
            //You can leave that out and it'll just update as fast as the hardware will allow it.
            game.Run();
        }
    }
}

Current Available Functions

On OnLoad

Make sure to add these before base.OnLoad()

Make sure to add these after base.OnLoad()

On OnRenderFrame

3D Functions:

  1. Render3DObjects() => Renders the 3D objects to the screen, call before any 2D functions if mixing 2D with 3D
  2. RotateObject(float x, float y, float z, int handle) => Rotates the object passed in by the amounts pass in in each direction
  3. RotateTexturedObject(float x, float y, float z, int handle) => Rotates the textured object passed in by the amounts pass in in each direction
  4. ScaleObject(float scale, int handle) => Scales the object passed in by the amount pass
  5. TranslateObject(float x, float y, float z, int handle) => Translates the object by a vector passed in
  6. TranslateTexturedObject(float x, float y, float z, int handle) => Translates the textured object by a vector passed in

2D Functions:

  1. DrawRectangle(float x1, float y1, float x2, float y2, Color4 color)
  2. DrawLine(float x1, float y1, float x2, float y2, Color4 color)
  3. DrawEllipse(float x, float y, float radiusX, float radiusY, Color4 color)
  4. DrawTexturedLine(float x1, float y1, float u1, float v1, float x2, float y2, float u2, float v2, Texture texture, Color4 color)
  5. DrawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, Color4 color)
  6. DrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Color4 color)
  7. DrawText(string text, float x, float y, Font f, Color4 col, int TextAlign)
  8. drawTexturedRectangle() overloads
    1. DrawTexturedRectangle(float x1, float y1, float u1, float v1, float x2, float y2, float u2, float v2, string texturePath, Color4 color, TextureMinFilter min, TextureMagFilter mag)
    2. DrawTexturedRectangle(float x1, float y1, float u1, float v1, float x2, float y2, float u2, float v2, Bitmap textureBitmap, Color4 color, TextureMinFilter min, TextureMagFilter mag)
    3. DrawTexturedRectangle(float x1, float y1, float u1, float v1, float x2, float y2, float u2, float v2, Texture texture, Color4 color)
  9. drawTexturedQuad() overloads
    1. DrawTexturedQuad(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4, string texturePath, Color4 color, TextureMinFilter min, TextureMagFilter mag)
    2. DrawTexturedQuad(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4, Bitmap textureBitmap, Color4 color, TextureMinFilter min, TextureMagFilter mag)
    3. DrawTexturedQuad(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4, Texture texture, Color4 color)