Skip to content

Engine wrapper for the openTK library, makes a complicated library easy to use with simple functions.

License

Notifications You must be signed in to change notification settings

Timber1900/OpenTK-3D-Engine

Repository files navigation

OpenTK3DEngine

Todo:

  • Add drawPolygon Function (p5.js Triangle strip style),

  • Add internal support for fonts using the microsoft Font class to create a bitmap and font data, removing the need for external programs,

  • Make other 3D objects(cylinder, torus) not need .obj files to work

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()

  • Boolean UseDepthTest (*Default = false*) => Specifies if rendering engine will use depth test (When depth test is true alpha will not work, if false rendering will work based on the which functions are called first),
  • Boolean UseAlpha (*Default = true*) => Specifies if rendering engine will use alpha,
  • Boolean KeyboardAndMouseInput (*Default = true*) => Specifies if rendering engine will use default keyboard and mouse input,
  • Boolean showSet (*Default = false*) => Specifies if rendering engine open settings on esc,

Make sure to add these after base.OnLoad()

  • CreateMainLight(Vector3 pos, Color4 color) => Creates your main Light (static), make sure to run this function before any other 3D function but after Base.OnLoad(),
  • CreateCube(Color4 Color) => Creates a 3D cube of the color you specify, returns a handle for making modifications to the cube,
  • CreateSphere(Color4 Color) => Creates a 3D sphere of the color you specify, returns a handle for making modifications to the sphere,
  • CreateTorus(Color4 Color) => Creates a 3D torus of the color you specify, returns a handle for making modifications to the torus,
  • CreateCylinder(Color4 Color) => Creates a 3D cylinder of the color you specify, returns a handle for making modifications to the cylinder,
  • CreatePlane(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) => Creates a 3D plane of the color you specify, returns a handle for making modifications to the plane,
  • OpenTexturedObj(string obj, string texture) => Opens .obj file with an attached .png texture, returns a handle for making modifications to the object,
  • OpenObj(string obj, Color4 color) => Opens .obj file with no attached .png texture, returns a handle for making modifications to the object,

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)

About

Engine wrapper for the openTK library, makes a complicated library easy to use with simple functions.

Topics

Resources

License

Stars

Watchers

Forks