]> Git trees. - libqmvoc.git/commitdiff
- change so that it's not required to explicitly call
authorBenoît Jacob <jacob.benoit.1@gmail.com>
Wed, 28 Jun 2006 16:47:22 +0000 (16:47 +0000)
committerBenoît Jacob <jacob.benoit.1@gmail.com>
Wed, 28 Jun 2006 16:47:22 +0000 (16:47 +0000)
VertexArray::select() explicitly anymore before drawing

- basic GL text rendering stuff now (sort of) working. It's slow because
it's texture-based, but that'll change.

M    kalzium/src/kalziumglhelperclasses.h
M    kalzium/src/kalziumglwidget.cpp
M    kalzium/src/kalziumglhelperclasses.cpp

svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglhelperclasses.cpp; revision=555886

kalzium/kalziumglhelperclasses.cpp
kalzium/kalziumglhelperclasses.h
kalzium/kalziumglwidget.cpp

index 49f9f7d377c8c14407a16ff4afa74433ea9bc0d7..5756a70f18ebd7d3e56335ba505fb5027f1b30e3 100644 (file)
@@ -72,14 +72,6 @@ VertexArray::~VertexArray()
        if( m_normalBuffer ) delete [] m_normalBuffer;
 }
 
-void VertexArray::select()
-{
-       glEnableClientState( GL_VERTEX_ARRAY );
-       glEnableClientState( GL_NORMAL_ARRAY );
-       glVertexPointer( 3, GL_FLOAT, 0, m_vertexBuffer );
-       glNormalPointer( GL_FLOAT, 0, m_normalBuffer );
-}
-
 bool VertexArray::allocateBuffers()
 {
        if( m_vertexCount > 65536 ) return false;
@@ -335,3 +327,94 @@ void Cylinder::initialize()
 
        m_isInitialized = true;
 }
+
+TextPainter::TextPainter()
+{
+       m_width = 0;
+       m_height = 0;
+       m_image = 0;
+       m_painter = 0;
+       m_fontMetrics = 0;
+}
+
+TextPainter::~TextPainter()
+{
+       if( m_image ) delete m_image;
+       if( m_painter ) delete m_painter;
+       if( m_fontMetrics ) delete m_fontMetrics;
+}
+
+bool TextPainter::print( QGLWidget *glwidget, int x, int y, const QString &string)
+{
+       glDisable( GL_LIGHTING );
+       glEnable(GL_TEXTURE_2D);
+       glEnable( GL_BLEND );
+
+       if( ! m_painter )
+       {
+               m_painter = new QPainter();
+               if( ! m_painter ) return false;
+       }
+
+       if( ! m_fontMetrics )
+       {
+               
+               m_fontMetrics = new QFontMetrics(glwidget->font());
+               if( ! m_fontMetrics ) return false;
+       }
+
+       int new_width = m_fontMetrics->width( string );
+       int new_height = m_fontMetrics->height();
+       
+       if(new_width == 0 || new_height == 0)
+       {
+               return false;
+       }
+
+       if( new_width > m_width || new_height > m_height )
+       {
+               if( m_image ) delete m_image;
+               m_width = ( new_width > m_width ) ? new_width : m_width;
+               m_height = ( new_height > m_height ) ? new_height : m_height;
+               m_image = new QImage( m_width, m_height, QImage::Format_ARGB32 );
+       }
+
+       m_painter->begin( m_image );
+       m_painter->setFont(glwidget->font());
+       m_painter->setRenderHint(QPainter::TextAntialiasing);
+       //painter.setBackground(Qt::black);
+       m_painter->setBrush(Qt::white);
+       m_painter->eraseRect( 0, 0, m_width, m_height );
+
+       //painter.drawText ( 0, 0, s );
+       m_painter->drawText ( 0, m_height, string );
+       m_painter->end();
+
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+       glwidget->bindTexture( *m_image );
+       glMatrixMode( GL_PROJECTION );
+       glPushMatrix();
+       glLoadIdentity();
+       glOrtho( 0, glwidget->width(), 0, glwidget->height(), -1, 1 );
+       glMatrixMode( GL_MODELVIEW );
+       glPushMatrix();
+       glLoadIdentity();
+       glBegin(GL_QUADS);
+       glTexCoord2f( 0, 0);
+       glVertex2f( x , y );
+       glTexCoord2f( 1, 0);
+       glVertex2f( x+m_width , y );
+       glTexCoord2f( 1, 1);
+       glVertex2f( x+m_width , y+m_height );
+       glTexCoord2f( 0, 1);
+       glVertex2f( x , y+m_height );
+       glEnd();
+       glDisable( GL_TEXTURE_2D);
+       glDisable( GL_BLEND );
+       glPopMatrix();
+       glMatrixMode( GL_PROJECTION );
+       glPopMatrix();
+       glMatrixMode( GL_MODELVIEW );
+       return true;
+}
index b285f41d64b79f312e0456139ffb756ef4479eda..8d25721c856aaa9dc5c6ff3d13bc0d5d07c4f9c5 100644 (file)
@@ -224,9 +224,14 @@ class VertexArray
        public:
                VertexArray();
                virtual ~VertexArray();
-               virtual void select();
+               virtual inline void select()
+               {
+                       glVertexPointer( 3, GL_FLOAT, 0, m_vertexBuffer );
+                       glNormalPointer( GL_FLOAT, 0, m_normalBuffer );
+               }
                virtual inline void draw()
                {
+                       select();
                        glDrawElements( m_mode, m_indexCount,
                                GL_UNSIGNED_SHORT, m_indexBuffer );
                }
@@ -276,6 +281,7 @@ class Cylinder : public VertexArray
                virtual void setup( int detail, GLfloat radius );
                virtual inline void draw()
                {
+                       select();
                        glDrawArrays( m_mode, 0, m_vertexCount );
                }
 };
@@ -289,99 +295,9 @@ class TextPainter
                QFontMetrics *m_fontMetrics;
 
        public:
-               TextPainter()
-               {
-                       m_width = 0;
-                       m_height = 0;
-                       m_image = 0;
-                       m_painter = 0;
-                       m_fontMetrics = 0;
-               }
-               ~TextPainter()
-               {
-                       if( m_image ) delete m_image;
-                       if( m_painter ) delete m_painter;
-                       if( m_fontMetrics ) delete m_fontMetrics;
-               }
-               bool print( QGLWidget *glwidget, int x, int y, const QString &string)
-               {
-                       glDisable( GL_LIGHTING );
-                       glEnable(GL_TEXTURE_2D);
-                       
-                       /*if( ! m_font )
-                       {
-                               m_font = new QFont();
-                               if( ! m_font ) return false;
-                       }*/
-
-                       const QFont &m_font = (glwidget->font());
-
-                       if( ! m_painter )
-                       {
-                               m_painter = new QPainter();
-                               if( ! m_painter ) return false;
-                       }
-
-                       m_painter->setFont(m_font);
-
-                       if( ! m_fontMetrics )
-                       {
-                               
-                               m_fontMetrics = new QFontMetrics(m_font);
-                               if( ! m_fontMetrics ) return false;
-                       }
-               
-                       int new_width = m_fontMetrics->width( string );
-                       int new_height = m_fontMetrics->height();
-                       
-                       if(new_width == 0 || new_height == 0)
-                       {
-                               return false;
-                       }
-
-                       if( new_width > m_width || new_height > m_height )
-                       {
-                               if( m_image ) delete m_image;
-                               m_width = ( new_width > m_width ) ? new_width : m_width;
-                               m_height = ( new_height > m_height ) ? new_height : m_height;
-                               m_image = new QImage( m_width, m_height, QImage::Format_ARGB32 );
-                       }
-               
-                       m_painter->begin( m_image );
-                       m_painter->setRenderHint(QPainter::TextAntialiasing);
-                       //painter.setBackground(Qt::black);
-                       m_painter->setBrush(Qt::white);
-                       m_painter->eraseRect( 0, 0, m_width, m_height );
-               
-                       //painter.drawText ( 0, 0, s );
-                       m_painter->drawText ( 0, m_height, string );
-                       m_painter->end();
-               
-                       glwidget->bindTexture( *m_image );
-                       glMatrixMode( GL_PROJECTION );
-                       glPushMatrix();
-                       glLoadIdentity();
-                       glOrtho( 0, glwidget->width(), 0, glwidget->height(), -1, 1 );
-                       glMatrixMode( GL_MODELVIEW );
-                       glPushMatrix();
-                       glLoadIdentity();
-                       glBegin(GL_QUADS);
-                       glTexCoord2f( 0, 0);
-                       glVertex2f( x , y );
-                       glTexCoord2f( 1, 0);
-                       glVertex2f( x+m_width , y );
-                       glTexCoord2f( 1, 1);
-                       glVertex2f( x+m_width , y+m_height );
-                       glTexCoord2f( 0, 1);
-                       glVertex2f( x , y+m_height );
-                       glEnd();
-                       glDisable( GL_TEXTURE_2D);
-                       glPopMatrix();
-                       glMatrixMode( GL_PROJECTION );
-                       glPopMatrix();
-                       glMatrixMode( GL_MODELVIEW );
-                       return true;
-               }
+               TextPainter::TextPainter();
+               TextPainter::~TextPainter();
+               bool TextPainter::print( QGLWidget *glwidget, int x, int y, const QString &string);
 };
 
 } // namespace KalziumGL
index 5e206052e6d56651970a0b28b07c1a0135bcb32b..1ca9145d113e23c77acbf8f24e55e0afc7380a91 100644 (file)
@@ -40,6 +40,8 @@ KalziumGLWidget::KalziumGLWidget( QWidget * parent )
        m_detail = 0;
        m_useFog = false;
        m_textPainter = 0;
+       m_inZoom = false;
+       m_inMeasure = false;
 
        ChooseStylePreset( PRESET_SPHERES_AND_BICOLOR_BONDS );
        
@@ -94,6 +96,9 @@ void KalziumGLWidget::initializeGL()
        glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL_EXT,
                GL_SEPARATE_SPECULAR_COLOR_EXT );
 
+       glEnableClientState( GL_VERTEX_ARRAY );
+       glEnableClientState( GL_NORMAL_ARRAY );
+
        setupObjects();
 
        m_textPainter = new TextPainter;
@@ -134,7 +139,6 @@ void KalziumGLWidget::paintGL()
        // prepare for rendering the spheres
        if( m_atomStyle == ATOM_SPHERE )
        {
-               m_sphere.select();
                glEnable( GL_LIGHTING );
        }
        else glDisable( GL_LIGHTING );
@@ -169,7 +173,6 @@ void KalziumGLWidget::paintGL()
                
                case BOND_CYLINDER_GRAY:
                case BOND_CYLINDER_BICOLOR:
-                       m_cylinder.select();
                        glEnable( GL_LIGHTING );
                        break;
                case BOND_DISABLED: break;
@@ -232,8 +235,6 @@ void KalziumGLWidget::paintGL()
        // now, paint a semitransparent sphere around the selected atoms
        if( m_selectedAtoms.count() > 0 )//there are items selected
        {
-               m_sphere.select();
-
                Color c( 0.4, 0.4, 1.0, 0.7 );
 
                GLFLOAT radius = m_molMinBondLength * 0.35;
@@ -283,13 +284,13 @@ void KalziumGLWidget::paintGL()
                s = QString::number( 1000 * frames /
                        double( new_time - old_time ),
                        'f', 1 );
-               s += " frames per second";
+               s += " frames per second" + QString( QChar( 962 ) );
                frames = 0;
                old_time = new_time;
        }
 
        glColor3f( 1.0, 1.0, 0.0 );
-       //m_textPainter->print( this, 20, 20, s );
+       m_textPainter->print( this, 20, 20, s );
 
        update();
 #endif