# OpenGL Loading
## Metadata
**Status**:: #x
**Zettel**:: #zettel/fleeting
**Created**:: [[2024-05-11]]
## Synopsis
Use a meta loader like
- [glew](https://glew.sourceforge.net/)
- [gl3w](https://github.com/skaslev/gl3w)
## Example to Use Glew
> [!code] conanfile.txt
```
[requires]
glfw/3.4
glew/2.2.0
[layout]
cmake_layout
[generators]
CMakeDeps
CMakeToolchain
```
> [!code] CMakeLists.txt
```cmake
find_package(glew REQUIRED)
target_link_libraries(mytarget glfw GLEW::GLEW)
```
> [!code] main.c
```c
#include <GL/glew.h>
#include <GLFW/glfw3.h>
nt main(void)
{
GLFWwindow *window;
/* Initialize the library */
if (!glfwInit())
{
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Init after GL context is available */
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
return -1;
}
/* 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();
}
glfwTerminate();
return 0;
}
```
See [full example](https://github.com/doitian/opengl-programming-guide/blob/main/src/c1-1.c).
### Build the Project
```shell
conan install . --build=missing
cmake --preset conan-default
cmake --build build --config Release
```
See [[Conan Debug Profile for Visual Studio]] to use the Debug profile.