Convert Figma logo to code with AI

JoeyDeVries logoLearnOpenGL

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com

10,784
2,756
10,784
149

Top Related Projects

2,691

2,329

OpenGL 3 and 4 with GLSL

Quick Overview

LearnOpenGL is a comprehensive OpenGL tutorial series and accompanying code repository created by Joey de Vries. It provides a structured approach to learning modern OpenGL, covering topics from basic rendering to advanced graphics techniques, making it an invaluable resource for both beginners and experienced developers looking to enhance their graphics programming skills.

Pros

  • Extensive coverage of OpenGL concepts, from basics to advanced topics
  • Well-structured tutorials with clear explanations and practical examples
  • Includes complete source code for all examples, making it easy to follow along
  • Regularly updated to include modern OpenGL practices and techniques

Cons

  • May be overwhelming for absolute beginners in graphics programming
  • Focuses primarily on OpenGL, with limited coverage of other graphics APIs
  • Some advanced topics might require additional resources for deeper understanding
  • Requires a solid foundation in C++ programming

Code Examples

  1. Setting up a basic OpenGL window using GLFW:
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
    if (window == NULL)
    {
        std::cout << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }

    glViewport(0, 0, 800, 600);

    while(!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();    
    }

    glfwTerminate();
    return 0;
}
  1. Creating and using a basic shader program:
#include <shader.h>

int main()
{
    // ... window setup code ...

    Shader ourShader("vertex.glsl", "fragment.glsl");

    while(!glfwWindowShouldClose(window))
    {
        // ... render loop ...
        ourShader.use();
        glDrawArrays(GL_TRIANGLES, 0, 3);
    }

    return 0;
}
  1. Loading and rendering a textured model:
#include <model.h>

int main()
{
    // ... window and shader setup ...

    Model ourModel("path/to/model.obj");

    while(!glfwWindowShouldClose(window))
    {
        // ... render loop ...
        ourShader.use();
        ourModel.Draw(ourShader);
    }

    return 0;
}

Getting Started

  1. Clone the repository: git clone https://github.com/JoeyDeVries/LearnOpenGL.git
  2. Install dependencies: GLFW, GLAD, and GLM
  3. Build the project using CMake:
    mkdir build && cd build
    cmake ..
    make
    
  4. Run the examples in the bin directory
  5. Follow the tutorials on learnopengl.com for detailed explanations and guidance

Competitor Comparisons

2,691

Pros of ogl

  • More concise tutorials, easier for beginners to grasp
  • Focuses on core OpenGL concepts without extra complexities
  • Includes some basic game development topics

Cons of ogl

  • Less comprehensive coverage of advanced topics
  • Older codebase, may not reflect the latest OpenGL best practices
  • Fewer examples and less detailed explanations

Code Comparison

LearnOpenGL:

glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

ogl:

GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

Both repositories provide similar code for setting up vertex arrays and buffers. LearnOpenGL tends to use more descriptive variable names and includes additional steps, making it easier for beginners to understand the process. The ogl repository uses more compact code, which may be preferred by experienced developers but could be less clear for newcomers.

Overall, LearnOpenGL offers a more comprehensive and up-to-date learning experience, while ogl provides a more concise introduction to core OpenGL concepts. The choice between the two depends on the learner's experience level and learning goals.

2,329

OpenGL 3 and 4 with GLSL

Pros of OpenGL

  • More comprehensive coverage of OpenGL features and techniques
  • Includes examples for both desktop and mobile (Android) platforms
  • Provides a wider range of advanced rendering techniques and effects

Cons of OpenGL

  • Less structured learning path for beginners
  • Documentation and explanations are not as detailed or beginner-friendly
  • Code organization may be more complex for newcomers to navigate

Code Comparison

LearnOpenGL:

glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

OpenGL:

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

Both repositories provide valuable resources for learning OpenGL, but they cater to different audiences. LearnOpenGL offers a more structured and beginner-friendly approach, while OpenGL provides a broader range of advanced techniques and platform coverage. The choice between them depends on the learner's experience level and specific goals in OpenGL development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

learnopengl.com code repository

Contains code samples for all chapters of Learn OpenGL and https://learnopengl.com.

Windows building

All relevant libraries are found in /libs and all DLLs found in /dlls (pre-)compiled for Windows. The CMake script knows where to find the libraries so just run CMake script and generate project of choice.

Keep in mind the supplied libraries were generated with a specific compiler version which may or may not work on your system (generating a large batch of link errors). In that case it's advised to build the libraries yourself from the source.

Linux building

First make sure you have CMake, Git, and GCC by typing as root (sudo) apt-get install g++ cmake git and then get the required packages: Using root (sudo) and type apt-get install libsoil-dev libglm-dev libassimp-dev libglew-dev libglfw3-dev libxinerama-dev libxcursor-dev libxi-dev libfreetype-dev libgl1-mesa-dev xorg-dev .

Build through CMake-gui: The source directory is LearnOpenGL and specify the build directory as LearnOpenGL/build. Creating the build directory within LearnOpenGL is important for linking to the resource files (it also will be ignored by Git). Hit configure and specify your compiler files (Unix Makefiles are recommended), resolve any missing directories or libraries, and then hit generate. Navigate to the build directory (cd LearnOpenGL/build) and type make in the terminal. This should generate the executables in the respective chapter folders.

Build through Cmake command line:

cd /path/to/LearnOpenGL
mkdir build && cd build
cmake ..
cmake --build .

Note that CodeBlocks or other IDEs may have issues running the programs due to problems finding the shader and resource files, however it should still be able to generate the executables. To work around this problem it is possible to set an environment variable to tell the tutorials where the resource files can be found. The environment variable is named LOGL_ROOT_PATH and may be set to the path to the root of the LearnOpenGL directory tree. For example:

`export LOGL_ROOT_PATH=/home/user/tutorials/LearnOpenGL`

Running ls $LOGL_ROOT_PATH should list, among other things, this README file and the resources directory.

Mac OS X building

Building on Mac OS X is fairly simple:

brew install cmake assimp glm glfw freetype
cmake -S . -B build
cmake --build build -j$(sysctl -n hw.logicalcpu)

Create Xcode project on Mac platform

Thanks @caochao: After cloning the repo, go to the root path of the repo, and run the command below:

mkdir xcode
cd xcode
cmake -G Xcode ..

Glitter

Polytonic created a project called Glitter that is a dead-simple boilerplate for OpenGL. Everything you need to run a single LearnOpenGL Project (including all libraries) and just that; nothing more. Perfect if you want to follow along with the chapters, without the hassle of having to manually compile and link all third party libraries!

Ports

Check out @srcres258's port in Rust here.