Back to index

salome-gui  6.5.0
Defines | Functions | Variables
GLViewer_Drawer.cxx File Reference
#include "GLViewer_Drawer.h"
#include "GLViewer_Object.h"
#include "GLViewer_Text.h"
#include "GLViewer_ViewFrame.h"
#include "GLViewer_ViewPort2d.h"
#include <QApplication>
#include <QImage>
#include <QPainter>
#include <QFile>
#include <GL/glx.h>
#include <gp_Pnt2d.hxx>

Go to the source code of this file.

Defines

#define TEXT_GAP   5
#define NB_TEX_COMP   2
#define TEX_ROW_LEN   32
#define TEX_ROW_GAP   2

Functions

static GLuint displayListBase (QFont *theFont)
 Generates list base for bitmap fonts.

Variables

GLfloat modelMatrix [16]
static int FirstSymbolNumber = 32
 code of first font symbol
static int LastSymbolNumber = 127
 code of last font symbol
GLubyte rasterVertex [5] = { 0x70, 0xf8, 0xf8, 0xf8, 0x70 }
GLubyte rasterCross [7] = { 0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82 }

Define Documentation

#define NB_TEX_COMP   2

Definition at line 47 of file GLViewer_Drawer.cxx.

#define TEX_ROW_GAP   2

Definition at line 51 of file GLViewer_Drawer.cxx.

#define TEX_ROW_LEN   32

Definition at line 49 of file GLViewer_Drawer.cxx.

#define TEXT_GAP   5

Definition at line 45 of file GLViewer_Drawer.cxx.


Function Documentation

static GLuint displayListBase ( QFont *  theFont) [static]

Generates list base for bitmap fonts.

Definition at line 367 of file GLViewer_Drawer.cxx.

{
  if ( !theFont )
    return 0;
  GLuint aList = 0;
  //static QMap<GLViewer_TexFindId, GLuint> fontCache;
  GLViewer_TexFindId aFindFont;
  aFindFont.myFontFamily = theFont->family();//theFont->toString();
  aFindFont.myIsBold = theFont->bold();
  aFindFont.myIsItal = theFont->italic();
  aFindFont.myIsUndl = theFont->underline();
  aFindFont.myPointSize = theFont->pointSize();

#ifdef WIN32
  HGLRC ctx = ::wglGetCurrentContext();
  if ( !ctx )
    return aList;  
  
  aFindFont.myViewPortId = (int)ctx;

  if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
    aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
  else
  {
    GLuint listBase = 0;
    QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
    for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
    {
      if ( it.key().myViewPortId == (int)ctx && it.value() > listBase )
        listBase = it.value();
    }
    listBase += 256;

    HDC glHdc = ::wglGetCurrentDC();
    ::SelectObject( glHdc, theFont->handle() );
    if ( !::wglUseFontBitmaps( glHdc, 0, 256, listBase ) )
      listBase = 0;
    aList = listBase;
    GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
  }
#else //X Window
  Display* aDisp = glXGetCurrentDisplay();
  if( !aDisp )
  {
#ifdef _DEBUG_
    printf( "Can't find current dislay\n" );
#endif
    return aList;
  }
  
  GLXContext aCont = glXGetCurrentContext();
  if( !aCont )
  {
#ifdef _DEBUG_
    printf( "Can't find current context\n" );
#endif
    return aList;
  }

  aFindFont.myViewPortId = size_t(aCont);

  if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
    aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
  else
  {
    GLuint listBase = 0;
    QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
    for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
    {
      if ( it.key().myViewPortId == size_t(aCont) && it.value() > listBase )
        listBase = it.value();
    }
    listBase += 256;
    
    //glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase );
    int aFontCont = 0;
    QString aFontDef = theFont->toString();
    char** xFontList = XListFonts( aDisp, aFontDef.toLatin1()/*aFindFont.myFontString.data()*/, 1, &aFontCont  );
    if( !theFont->handle() )
    {       
#ifdef _DEBUG_
      printf( "Can't load font %s. loading default font....\n", aFontDef.toLatin1().data()/*aFindFont.myFontString.data()*/ );
#endif
      QString aFontMask ("-*-*-*-r-*-*-");
      aFontMask += aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 );
#ifdef _DEBUG_
      printf( "Height of Default font: %s\n", aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ).data() );
#endif
      aFontMask += "-*-*-*-m-*-*-*";
      xFontList = XListFonts( aDisp, aFontMask.toLatin1().constData()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont  );
      if( aFontCont == 0 )
      {      
#ifdef _DEBUG_
        printf( "Can't load default font\n" );
#endif
        return 0;
      }
      glXUseXFont( (Font)(XLoadFont( aDisp,xFontList[0] )), 0, 256, listBase );
    }
    else
      glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase );
    
    aList = listBase;
    GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
  }

#endif

  return aList;
}

Variable Documentation

int FirstSymbolNumber = 32 [static]

code of first font symbol

Definition at line 57 of file GLViewer_Drawer.cxx.

int LastSymbolNumber = 127 [static]

code of last font symbol

Definition at line 59 of file GLViewer_Drawer.cxx.

GLfloat modelMatrix[16]

Definition at line 53 of file GLViewer_Drawer.cxx.

GLubyte rasterCross[7] = { 0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82 }

Definition at line 1113 of file GLViewer_Drawer.cxx.

GLubyte rasterVertex[5] = { 0x70, 0xf8, 0xf8, 0xf8, 0x70 }

Definition at line 1098 of file GLViewer_Drawer.cxx.