LightGL - A Lightweight OpenGL C# Wrapper Library
$ dotnet add package LightGLLightGL is a lightweight C# wrapper library for OpenGL, offering a concise, efficient, and cross-platform graphics rendering solution.
LightGL is built specifically for high-performance graphics rendering. Its call efficiency is almost identical to that of native C/C++ implementations, outperforming general-purpose OpenGL wrapper libraries.
Wiki: https://deepwiki.com/unknowall/LightGL , https://zread.ai/unknowall/LightGL
IGlContext interface provides dedicated implementations for different operating systems:
NSOpenGLContext, supporting macOS’s native OpenGL frameworkgit clone https://github.com/unknowall/LightGL.git
LightGL.slnReference the LightGL in your C# project, Refer to the following sample code to quickly implement basic rendering:
// 1. Create OpenGL context (window handle example)
IntPtr windowHandle = YourWindow.GetHandle(); // Replace with your actual window handle
IGlContext context = GlContextFactory.CreateFromWindowHandle(windowHandle, 3, 2, GlProfile.Core);
context.MakeCurrent();
// 2. Initialize shaders
var vertexShaderCode = @"
attribute vec4 position;
attribute vec2 texCoord;
varying vec2 v_texCoord;
void main() {
gl_Position = position;
v_texCoord = texCoord;
}";
var fragmentShaderCode = @"
uniform sampler2D u_texture;
varying vec2 v_texCoord;
void main() {
gl_FragColor = texture2D(u_texture, v_texCoord);
}";
GLShader shader = new GLShader(vertexShaderCode, fragmentShaderCode);
// 3. Create vertex buffer
float[] vertices = {
-1.0f, -1.0f, 0.0f, 0.0f, // Bottom-left
1.0f, -1.0f, 1.0f, 0.0f, // Bottom-right
1.0f, 1.0f, 1.0f, 1.0f, // Top-right
-1.0f, 1.0f, 0.0f, 1.0f // Top-left
};
GLBuffer vertexBuffer = GLBuffer.Create();
vertexBuffer.SetData(vertices);
// 4. Create texture
GLTexture2D texture = GLTexture2D.Create()
.SetFormat(TextureFormat.RGBA)
.SetSize(2, 2)
.SetData(new uint[] { 0xFF0000FF, 0xFF00FFFF, 0xFFFF00FF, 0xFFFFFFFF });
// 5. Render loop
bool running = true;
while (running)
{
// Clear buffers
GL.ClearColor(0.1f, 0.1f, 0.1f, 1.0f);
GL.Clear(GL.GL_COLOR_BUFFER_BIT);
// Bind resources and draw
shader.Use();
shader.SetUniform("u_texture", texture);
vertexBuffer.Bind();
GL.DrawArrays(GL.GL_TRIANGLE_FAN, 0, 4);
// Swap buffers
context.SwapBuffers();
// Handle window events (implement based on your windowing framework)
HandleWindowEvents(ref running);
}
// Release resources
shader.Dispose();
vertexBuffer.Dispose();
texture.Dispose();
context.Dispose();
Demo projectfeature/xxx) or a bugfix branch (fix/xxx)This project is licensed under the MIT License, which permits: