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.hand add another variable calledvbo_normalsto the file:QOpenGLBuffer* vbo_uvs; QOpenGLBuffer* vbo_normals; QOpenGLTexture* texture;
- Open
renderwindow.cppand add another array callednormalsto 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...