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  ·  Fonctions  · 

How to use X11 overlays with the Qt OpenGL extension

X11 overlays are a powerful mechanism for drawing annotations etc., on top of an image without destroying it, thus saving a great deal of image rendering time. For more information, consult the highly recommended book OpenGL Programming for the X Window System (Mark Kilgard, Addison Wesley Developers Press 1996).

Warning: From version 5.0 onwards, the Qt OpenGL Extension includes direct support for the use of OpenGL overlays. For many uses of overlays, this makes the technique described below redundant. See the overlay example program. The following is a discussion on how to use non-QGL widgets in overlay planes.

In the typical case, X11 overlays can easily be used together with the current version of Qt and the Qt OpenGL Extension. The following requirements apply:

  1. Your X server and graphics card/hardware must support overlays. For many X servers, overlay support can be turned on with a configuration option; consult your X server installation documentation.

  2. Your X server must (be configured to) use an overlay visual as the default visual. Most modern X servers do this, since this has the added advantage that pop-up menus, overlapping windows etc., will not destroy underlying images in the main plane, thereby avoiding expensive redraws.

  3. The best (deepest) visual for OpenGL rendering is in the main plane. This is the normal case. Typically, X servers that support overlays provide a 24 bit deep TrueColor visual in the main plane, and an 8 bit PseudoColor (default) visual in the overlay plane.

The provided example program X11 overlay will check for these and report if anything is wrong. See About X11 Visuals, below for more information.

How it works

Given the above, a QGLWidget will by default use the main plane visual, while all other widgets will use the overlay visual. Thus, we can place a normal widget on top of the QGLWidget, and do drawing on it, without destroying the image in the OpenGL window. In other words, we can use all the drawing capabilities of QPainter to draw the annotations, rubberbands, etc. For the typical use of overlays, this is much easier than using OpenGL for rendering the annotations.

An overlay plane has a specific color called the transparent color. Pixels drawn in this color will not be visible; instead the underlying OpenGL image will show through. In the example program X11 overlay, the file main.cpp contains a routine that returns a QColor containing the transparent color. For the overlay widget, you will typically want to set the background color to the transparent color, so that the OpenGL image shows through except where explicitly overpainted.

Note: to use this technique, you must not use the "ManyColor" or "TrueColor" ColorSpec for QApplication, because this will force the normal Qt widgets to use a TrueColor visual, which will typically be in the main plane, not in the overlay plane as desired.

About X11 visuals

The utilities directory contains two small programs that can help you determine the capabilities of your X server. These programs are from the OpenGL book mentioned above, see utilities/NOTICE for copyright information. The full set of example programs from this book is available at ftp://ftp.sgi.com/pub/opengl/opengl_for_x/.

glxvisuals will list all the GL-capable visuals the X server provides, together with the depth and other GL-specific information for each. Note especially the column "lvl"; a number in this column means the visual is in an overlay plane.

sovinfo will list all available visuals, and provides special transparency information for overlay visuals.

The X11 overlay example program will output what visual is used for the normal Qt widgets, and what visual is used by the QGLWidget.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 79
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Developer Network au hasard

Logo

Les bases

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

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 3.3
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