Book Image

Qt5 C++ GUI Programming Cookbook

By : Lee Zhi Eng
Book Image

Qt5 C++ GUI Programming Cookbook

By: Lee Zhi Eng

Overview of this book

With the advancement of computer technology, the software market is exploding with tons of software choices for the user, making their expectations higher in terms of functionality and the look and feel of the application. Therefore, improving the visual quality of your application is vital in order to overcome the market competition and stand out from the crowd. This book will teach you how to develop functional and appealing software using Qt5 through multiple projects that are interesting and fun. This book covers a variety of topics such as look-and-feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. You will learn tons of useful information, and enjoy the process of working on the creative projects provided in this book
Table of Contents (16 chapters)
Qt5 C++ GUI Programming Cookbook
About the Author
About the Reviewer

Texturing in OpenGL

OpenGL allows us to map an image (also referred to as a texture) to a 3D shape or polygon. This process is also called texture mapping. Qt appears to be the best combination with OpenGL in this case because it provides an easy way to load images that belong to one of the common formats (BMP, JPEG, PNG, TARGA, TIFF, and so on) and you don't have to implement it by yourself. We will use the previous example with a spinning cube and try to map it with a texture!

How to do it…

  1. First of all, open up mainwindow.h and add the following header to it:

    #include <QGLWidget>
  2. Next, declare an array that stores the texture IDs created by OpenGL. We will be using it later when it comes to rendering:

      QOpenGLContext* context;
      QOpenGLFunctions* openGLFunctions;
      float rotation;
      GLuint texID[1];
  3. After that, open up mainwindow.cpp and add the following code to initializeGL() to load the texture file:

    void MainWindow::initializeGL()
      // Enable Z-buffer depth test