2021-09-04 11:41:39 +00:00
|
|
|
#define GLAD_GL_IMPLEMENTATION
|
2020-06-03 18:46:22 +00:00
|
|
|
#include <glad/gl.h>
|
2021-09-04 11:41:39 +00:00
|
|
|
#define GLFW_INCLUDE_NONE
|
2020-06-03 18:46:22 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2020-07-15 12:19:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
|
|
|
}
|
2020-06-03 18:46:22 +00:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
GLFWwindow* window;
|
|
|
|
GLFWusercontext* usercontext;
|
|
|
|
|
2020-07-15 12:19:47 +00:00
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
2020-06-03 18:46:22 +00:00
|
|
|
/* Initialize the library */
|
|
|
|
if (!glfwInit())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Create a windowed mode window and its OpenGL context */
|
|
|
|
window = glfwCreateWindow(640, 480, "User Context", NULL, NULL);
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make the window's context current */
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
gladLoadGL(glfwGetProcAddress);
|
|
|
|
|
|
|
|
/* make a new context */
|
|
|
|
usercontext = glfwCreateUserContext(window);
|
|
|
|
if (!usercontext)
|
|
|
|
{
|
2020-07-15 12:19:47 +00:00
|
|
|
fprintf(stderr, "Failed to create user context\n");
|
2020-06-03 18:46:22 +00:00
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-07-15 12:19:47 +00:00
|
|
|
|
2020-06-03 18:46:22 +00:00
|
|
|
/* set the user context current */
|
|
|
|
glfwMakeUserContextCurrent(usercontext);
|
|
|
|
|
2021-03-23 18:45:29 +00:00
|
|
|
if (glfwGetCurrentContext() != NULL)
|
2020-07-15 12:19:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Current glfw window context not NULL after glfwMakeUserContextCurrent\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
2021-03-23 18:45:29 +00:00
|
|
|
if (glfwGetCurrentUserContext() != usercontext)
|
2020-07-15 12:19:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Current user context not correct after glfwMakeUserContextCurrent\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-06-03 18:46:22 +00:00
|
|
|
/* set the window context current */
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
2021-03-23 18:45:29 +00:00
|
|
|
if (glfwGetCurrentUserContext() != NULL)
|
2020-07-15 12:19:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Current user context not NULL after glfwMakeContextCurrent\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
2021-03-23 18:45:29 +00:00
|
|
|
if (glfwGetCurrentContext() != window)
|
2020-07-15 12:19:47 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Current glfw window context not correct after glfwMakeContextCurrent\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-03-23 12:37:54 +00:00
|
|
|
glClearColor( 0.4f, 0.3f, 0.4f, 1.0f );
|
2020-06-03 18:46:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Loop until the user closes the window */
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
|
|
{
|
|
|
|
/* Render here */
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
/* Swap front and back buffers */
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
|
|
|
|
/* Poll for and process events */
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwDestroyUserContext(usercontext);
|
|
|
|
glfwTerminate();
|
|
|
|
return 0;
|
|
|
|
}
|