Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Hello GL ES Example

The Hello GL ES example is the Hello GL Example ported to OpenGL ES. It also included some effects from the OpenGL Overpainting Example.

A complete introduction to OpenGL ES and a description of all differences between OpenGL and OpenGL ES is out of the scope of this document; but we will describe some of the major issues and differences.

Since Hello GL ES is a direct port of standard OpenGL code, it is a fairly good example for porting OpenGL code to OpenGL ES.

Using QGLWidget

QGLWidget can be used for OpenGL ES similar to the way it is used with standard OpenGL; but there are some differences. We use EGL 1.0 to embedd the OpenGL ES window within the native window manager. In QGLWidget::initializeGL() we initialize OpenGL ES.

Porting OpenGL to OpenGL ES

Since OpenGL ES is missing the immediate mode and does not support quads, we have to create triangle arrays.

We create a quad by adding vertices to a QList of vertices. We create both sides of the quad and hardcode a distance of 0.05f. We also compute the correct normal for each face and store them in another QList.


And then we convert the complete list of vertexes and the list of normals into the native OpenGL ES format that we can use with the OpenGL ES API.


In paintQtLogo() we draw the triangle array using OpenGL ES. We use q_vertexTypeEnum to abstract the fact that our vertex and normal arrays are either in float or in fixed point format.



Using QGLPainter

Since the QGLPainter is slower for OpenGL ES we paint the bubbles with the rasterizer and cache them in a QImage. This happends only once during the initialiazation.


For each bubble this QImage is then drawn to the QGLWidget by using the according QPainter with transparency enabled.


Another difference beetwen OpenGL and OpenGL ES is that OpenGL ES does not support glPushAttrib(GL_ALL_ATTRIB_BITS). So we have to restore all the OpenGL states ourselves, after we created the QPainter in GLWidget::paintGL().


Setting up up the model view matrix and setting the right OpenGL states is done in the same way as for standard OpenGL.


Now we have to restore the OpenGL state for the QPainter. This is not done automatically for OpenGL ES.


Now we use the QPainter to draw the transparent bubbles.


In the end, we calculate the framerate and display it using the QPainter again.


After we finished all the drawing operations we swap the screen buffer.



Summary

Similar to the Hello GL Example, we subclass QGLWidget to render a 3D scene using OpenGL ES calls. QGLWidget is a subclass of QWidget. Hence, its QGLWidget's subclasses can be placed in layouts and provided with interactive features just like normal custom widgets.

QGLWidget allows pure OpenGL ES rendering to be mixed with QPainter calls, but care must be taken to maintain the state of the OpenGL ES implementation.

Files:

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web