Using GLFW 3 as a Window and Context Creator
Cryru opened this issue · comments
I'm trying to migrate to OpenGL.Net using GLFW3 with these bindings (https://github.com/realvictorprm/GLFW3.NET) and I'm getting a black window with no errors.
I'm having trouble understanding how to interface the contexts between the two libraries, and have so far written this:
Glfw.Init();
Glfw.WindowHint((int) State.ContextVersionMajor, 3);
Glfw.WindowHint((int) State.ContextVersionMinor, 3);
Glfw.WindowHint((int) State.OpenglForwardCompat, 1);
Glfw.WindowHint((int) State.OpenglProfile, (int) State.OpenglCoreProfile);
Glfw.WindowHint((int) State.OpenglDebugContext, 1);
Gl.Initialize();
GLFWwindow win = Glfw.CreateWindow(settings.WindowWidth, settings.WindowHeight, settings.WindowTitle,
null, null);
Glfw.MakeContextCurrent(win);
Gl.BindAPI();
This works for me:
static void Main(string[] args)
{
GLFWwindow mainWindow = Glfw.CreateWindow(800, 600, "Hello World", null, null);
if (mainWindow == null)
{
Glfw.Terminate();
return;
}
Gl.Initialize();
Glfw.MakeContextCurrent(mainWindow);
System.Console.WriteLine(Gl.CurrentVersion);
System.Console.WriteLine(Gl.CurrentShadingVersion);
while (Glfw.WindowShouldClose(mainWindow) <= 0)
{
Glfw.PollEvents();
Render();
Glfw.SwapBuffers(mainWindow);
}
Glfw.Terminate();
}
public static void Render()
{
Gl.Viewport(0, 0, 800, 600);
Gl.Clear(ClearBufferMask.ColorBufferBit);
Gl.MatrixMode(MatrixMode.Projection);
Gl.LoadIdentity();
Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0);
Gl.MatrixMode(MatrixMode.Modelview);
Gl.LoadIdentity();
Gl.Begin(PrimitiveType.Triangles);
Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
Gl.End();
}