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;
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;
+}
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 );
}
virtual void setup( int detail, GLfloat radius );
virtual inline void draw()
{
+ select();
glDrawArrays( m_mode, 0, m_vertexCount );
}
};
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
m_detail = 0;
m_useFog = false;
m_textPainter = 0;
+ m_inZoom = false;
+ m_inMeasure = false;
ChooseStylePreset( PRESET_SPHERES_AND_BICOLOR_BONDS );
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;
// prepare for rendering the spheres
if( m_atomStyle == ATOM_SPHERE )
{
- m_sphere.select();
glEnable( GL_LIGHTING );
}
else glDisable( GL_LIGHTING );
case BOND_CYLINDER_GRAY:
case BOND_CYLINDER_BICOLOR:
- m_cylinder.select();
glEnable( GL_LIGHTING );
break;
case BOND_DISABLED: break;
// 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;
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