Basic lighting in OpenGL
In this example, we will learn how to add a simple point light to our 3D scene by using OpenGL and Qt 6.
How to do it…
Let’s get started by following these steps:
- Again, we will use the previous example and add a point light near the spinning cube. Open up
renderwindow.h
and add another variable calledvbo_normals
to the file:QOpenGLBuffer* vbo_uvs; QOpenGLBuffer* vbo_normals; QOpenGLTexture* texture;
- Open
renderwindow.cpp
and add another array callednormals
to theinitializeGL()
function:GLfloat normals[] = { 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f...