Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Qt5 C++ GUI Programming Cookbook

You're reading from   Qt5 C++ GUI Programming Cookbook Design and build a functional, appealing, and user-friendly graphical user interface

Arrow left icon
Product type Paperback
Published in Jul 2016
Publisher Packt
ISBN-13 9781783280278
Length 300 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Eng Eng
Author Profile Icon Eng
Eng
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Qt5 C++ GUI Programming Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Look and Feel Customization FREE CHAPTER 2. States and Animations 3. QPainter and 2D Graphics 4. OpenGL Implementation 5. Building a Touch Screen Application with Qt5 6. XML Parsing Made Easy 7. Conversion Library 8. Accessing Databases 9. Developing a Web Application Using Qt Web Engine Index

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:

    private:
      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
      glEnable...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images