{"id":19520305,"url":"https://github.com/henryhale/opengl","last_synced_at":"2026-05-13T08:08:20.898Z","repository":{"id":205524502,"uuid":"714449706","full_name":"henryhale/opengl","owner":"henryhale","description":"🖌️ Get started with OpenGL (Open Graphics Library)","archived":false,"fork":false,"pushed_at":"2024-06-06T07:36:50.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-08T13:37:37.449Z","etag":null,"topics":["cpp","glut","glut-library","graphics","graphics-programming","henryhale","make","opengl","opengl-tutorial"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henryhale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-04T22:22:20.000Z","updated_at":"2024-06-06T07:36:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"d39b61c7-e2dc-4a06-91d5-63f2342a3a3c","html_url":"https://github.com/henryhale/opengl","commit_stats":null,"previous_names":["henryhale/opengl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fopengl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fopengl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fopengl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fopengl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henryhale","download_url":"https://codeload.github.com/henryhale/opengl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240768256,"owners_count":19854422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","glut","glut-library","graphics","graphics-programming","henryhale","make","opengl","opengl-tutorial"],"created_at":"2024-11-11T00:24:53.165Z","updated_at":"2026-05-13T08:08:15.871Z","avatar_url":"https://github.com/henryhale.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenGL\n\n## Overview\nOpenGL stands for Open Graphics Library.\n\n\u003e_\"It is a cross-language, cross-platform application programming interface \n\u003efor rendering 2D and 3D vector graphics. The API is typically used to \n\u003einteract with a graphics processing unit (GPU), to achieve hardware-\n\u003eaccelerated rendering.\" - [Wikipedia](https://wikipedia.org/wiki/OpenGL)_\n\nThe OpenGL API only deals with rendering graphics. Hardware vendors, the \nGPU manufacturers are responsible for writing the implementations (drivers)\nof the OpenGL rendering system. OpenGL does not provide functons for managing \ninput, audio or drawing windows.\n\n\u003eEach graphics card supports a specific version of OpenGL and so updating your graphics \n\u003edrivers is recommended. However, there exists software implementations of OpenGL \n\u003esuch as Mesa.\n\nIn addition to having a low-level graphics rendering API, OpenGL is event-driven \nand offers maximal portability since it is operating system-independent, \ndisplay-device and window-system independent.\n\nAs a programmer, you can use OpenGL to write graphics programs. Your programs \nonly respond to events such as mouse - clicks, keyboard - keypress, window - \nreshape and others. The operating system maintains an event queue that takes in\nuser-defined callback functions (event listeners) and each invoked when a certain\nevent is triggered.\n\nOpenGL has a few variants such as OpenGL ES for mobile devices and WebGL - a JavaScript \nimplementation of OpenGL ES 2.0\n\nThere are multiple language bindings for OpenGL for example:\n- JavaScript ([WebGL](https://developer.mozilla.org/docs/Web/API/WebGL_API) \nfor browser-based 3D rendering)\n- C/C++\n- Java, and others.\n\nThis repository aims to help you get started with OpenGL by creating a \nbasic program in C++.\n\n## Installation\nThe OpenGL Utility Toolkit (GLUT) library comes with the OpenGL library and\nminimal window management for fast prototyping.\n\n### Linux (Debian-based OS)\n\nLoad updates and update packages to their latest version\n```sh\nsudo apt update \u0026\u0026 sudo apt upgrade\n```\n\nInstall OpenGL\n```sh\nsudo apt install freeglut3-dev\n```\n\nVerify the installation\n```sh\ndpkg -L freeglut3-dev\n```\n\n## Getting Started\n\nCreate a c++ file: `main.cpp` and add the GLUT header file\n```cpp\n#include \u003cGL/glut.h\u003e\n\n// code goes here\n```\n\nEvery OpenGL program must register a display callback function to render the \nobjects on the screen. For now, just add its prototype\n```cpp\n...\nvoid display(void);\n```\n\nIn your main function, initialize GLUT with the command line arguments and create\na new window within which the graphics will be rendered. It is from the created \nwindow that events are triggered.\n```cpp\n...\nint main(int argc, char* argv[])\n{\n    // initializes GLUT\n    glutInit(\u0026argc, argv);\n\n    // set display mode (single buffer with RGB colors \n    // since there are no animations\n    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);\n\n    // set window initial position\n    glutInitWindowPosition(200, 300);\n    \n    // set window initial size\n    glutInitWindowSize(400, 400);\n\n    // create the window with a title e.g \"Hello OpenGL\"\n    glutCreateWindow(\"Hello OpenGL\");\n\n    // register the display function, triggered whenever a new \n    // frame is required\n    glutDisplayFunc(display);\n\n    // start the event loop: the system will listen for events \n    // and trigger their respective callback functions\n    glutMainLoop();\n}\n```\n\nHere is how you can implement the `display` function to render a 2D triangle using \nOpenGL (notice that OpenGL functions begin with `gl` and not `glut`).\n```cpp\n...\n// function that draws on the canvas (window in this case)\nvoid display(void)\n{\n    // set the clear color (more like the color of the rubber)\n    glClearColor(0, 0, 0, 1);\n    \n    // clear the display using the clear color\n    glClear(GL_COLOR_BUFFER_BIT);\n\n    // start drawing a polygon\n    glBegin(GL_POLYGON);\n        // set the paint color to red and draw a vertex\n        glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.5f, 0.0f);\n        // blue corner\n        glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(0.0f, 0.5f);\n        // green corner\n        glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(0.5f, 0.0f);\n    // finish the polygon\n    glEnd();\n\n    // send the polygon data for rendering on the window\n    glFlush();\n}\n```\n\nFind the source code for this demo [here](./main.cpp).\n\n## Building\n\nTo build and run the cpp file, run the following command:\n```sh\ng++ main.cpp -o main -lGL -lGLU -lglut \u0026\u0026 ./main\n```\n\nThe output is a new window titled `Hello OpenGL` containing a shaded 2D triangle.\n\n![2D triangle using OpenGL](./screenshot.png)\n\n## More examples\n\n- [Digital clock](./example/) - there is a simple digital \nclock program using OpenGL in the [`example`](./example/) subfolder.\n    ![](example/screenshot.png)\n\n\n## References\n\n- [OpenGL.org](https://www.opengl.org/)\n- [Khonos.org - OpenGL](https://www.khronos.org/opengl/wiki/Getting_Started)\n- [Wikipedia - OpenGL](https://en.wikipedia.org/wiki/OpenGL)\n\n## License\n\nCopyright (c) 2023 [Henry Hale](https://github.com/henryhale).\n\nReleased under the [MIT License](./LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhale%2Fopengl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryhale%2Fopengl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhale%2Fopengl/lists"}