Great simple trick - I would like to tell how do you write simple with C#


#1

Hello everyone, I am working as C# developer and I want show you if you have not problem.

Getting started with create simple window with SDL2-CS and OpenGL-Wrapper

using System;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using SDL2;
namespace MonoLife.Client
{
    public class DisplayManager
    {
        protected static IntPtr window;
        protected static uint windowID;
        protected static IntPtr context;
        protected static bool isClosed = false;

        public static void CreateDisplay(string title, int width, int height)
        {
            if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) != 0)
            {
                Console.WriteLine("SDL_Init Error:", SDL.SDL_GetError());
            }

            window = SDL.SDL_CreateWindow(title, SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL);
            windowID = SDL.SDL_GetWindowID(window);

            SDL.SDL_GL_CreateContext(window);
            GraphicsContext.CurrentContext = context;
            GL.LoadAll(SDL.SDL_GL_GetProcAddress);
        }

        public static void UpdateDisplay()
        {
            SDL.SDL_GL_SwapWindow(window);
            SDL.SDL_UpdateWindowSurface(window);
        }

        public static bool WaitForClose
        {
            get
            {
                return isClosed;
            }
        }

        public static void InputDisplay(SDL.SDL_Event evt)
        {
            while (SDL.SDL_PollEvent(out evt) != 0)
            {
                if (evt.type == SDL.SDL_EventType.SDL_QUIT)
                {
                    isClosed = true;
                    break;
                }

                if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN)
                {
                    if (evt.key.keysym.sym == SDL.SDL_Keycode.SDLK_ESCAPE)
                    {
                        isClosed = true;
                        break;
                    }
                }

                if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED)
                {
                    int screen_width = evt.window.data1;
                    int screen_height = evt.window.data2;
                    GL.Viewport(0, 0, screen_width, screen_height);
                }
            }
        }

        public static void DestoryDisplay()
        {
            SDL.SDL_GL_DeleteContext(context);
            SDL.SDL_DestroyWindow(window);
            SDL.SDL_Quit();
        }
    }
}

There are simple methods like LwjGL 2.9x

I have found similar solution like this.

using System;
using MonoLife.Client;
using SDL2;

namespace MonoLife
{
    class MainClass
    {
        protected static SDL.SDL_Event systemEvent;

        [STAThread]
        static void Main(string[] args)
        {
            DisplayManager.CreateDisplay("Hello Game", 640, 480);
            // game initalization like GL commands for preparations or game's arguments too like for statement with if else etc..


            // end of game initalization
            while(!DisplayManager.WaitForClose)
            {
                DisplayManager.UpdateDisplay();
                // game logic


                // end of game logic
                DisplayManager.InputDisplay(systemEvent);
                // game input manager

                
                // end of game input managers
            }
            // destory or deletion of game logic like shader.CleanUp or model.CleanUp or GL comand GL.DeleteBuffer(vbo);


            // end of destory or deletion of game logic
            DisplayManager.DestoryDisplay();
        }
    }
}

Result:

That was it like LwjGL 2.9

I will create any new tutorials :smiley:

PS: Thanks for welcome and I am sorry for my bad English. I am deaf because I was bullying by bad people:( I swear that I will help your development if you would like to care with SDL2-CS by Ethan Lee ( aka. flibitijibibo ) - He is really good library creator for SDL2, SDL2-Image and more.

I would like to improve for next OpenGL wrapper for SDL2-CS

// UPDATE:

I add new many features of OpenGL, ModernOpenGL, VulkanGL, DirectX and more I am working it.

I would like to show about my own custom SDL2-CS with built-in wrappers. I am hopeful for next release for C# Programming - Don’t worry!

PS: If I am wrong for Community than you should tell me. Thanks! Because Ethan Lee suggests me.


#2

Hello everyone are you there?? I want know how do I fix with C# with Delegate with <T2>

// EDIT: Bad news:

delegate with <T> cannot able

Just wok around as public static void with <T> than it works fine

Now I am working with GL commands until. I check and I work hard.