Lighting and texture filter in OpenGL

In this example, we will learn how to apply different types of filtering effects such as point sampling, bilinear interpolation, and trilinear interpolation to the textures we use in OpenGL.

How to do it…

  1. Again, we will use the previous example and add a light near the spinning cube. Open up mainwindow.cpp and add the following code to the initializeGL() function:
    // Trilinear interpolation
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width(), texture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.bits()); ...

Get Qt5 C++ GUI Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.