In this example, we will learn how to add a simple point light to our 3D scene by using OpenGL and Qt 5.
Basic lighting in OpenGL
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 called vbo_normals to the file:
QOpenGLBuffer* vbo_uvs;
QOpenGLBuffer* vbo_normals;
QOpenGLTexture* texture;
- Open renderwindow.cpp and add another array called normals to the initializeGL() 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,
...