From b0f644f98b083928b89cd8ff5d0aaa6295676628 Mon Sep 17 00:00:00 2001 From: abd Date: Thu, 17 Nov 2005 13:33:12 +0000 Subject: [PATCH] no message --- src/GLViewer/GLViewer_Drawer.cxx | 104 ++++++++++++++++++++++++++++++- src/GLViewer/GLViewer_Drawer.h | 60 ++++++++++++++++-- 2 files changed, 155 insertions(+), 9 deletions(-) diff --git a/src/GLViewer/GLViewer_Drawer.cxx b/src/GLViewer/GLViewer_Drawer.cxx index 7f0cc9ba2..573e9f2dd 100644 --- a/src/GLViewer/GLViewer_Drawer.cxx +++ b/src/GLViewer/GLViewer_Drawer.cxx @@ -501,7 +501,10 @@ void GLViewer_Drawer::setAntialiasing(const bool on) // Function: loadTexture // Purpose : //======================================================================= -GLuint GLViewer_Drawer::loadTexture( const QString& fileName ) +GLuint GLViewer_Drawer::loadTexture( const QString& fileName, + GLint* x_size, + GLint* y_size, + GLint* t_size ) { QImage buf; if ( fileName.isEmpty() || !buf.load( fileName ) ) @@ -557,6 +560,15 @@ GLuint GLViewer_Drawer::loadTexture( const QString& fileName ) delete[] pixels; + if ( x_size ) + *(x_size) = w; + + if ( y_size ) + *(y_size) = h; + + if ( t_size ) + *(t_size) = size; + return texture; } @@ -566,7 +578,7 @@ GLuint GLViewer_Drawer::loadTexture( const QString& fileName ) //======================================================================= void GLViewer_Drawer::drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y ) { - float xScale = myXScale; + /*float xScale = myXScale; float yScale = myYScale; glColor4f( 1.0, 1.0, 1.0, 1.0 ); @@ -595,7 +607,93 @@ void GLViewer_Drawer::drawTexture( GLuint texture, GLint size, GLfloat x, GLfloa glFlush(); glDisable( GL_ALPHA_TEST ); - glDisable( GL_TEXTURE_2D ); + glDisable( GL_TEXTURE_2D );*/ + + drawTexture( texture, size, size, x, y ); +} + +//====================================================================== +// Function: drawTexture +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawTexture( GLuint texture, GLint x_size, GLint y_size, GLfloat x, GLfloat y ) +{ + /*float xScale = myXScale; + float yScale = myYScale; + + glColor4f( 1.0, 1.0, 1.0, 1.0 ); + + glEnable( GL_TEXTURE_2D ); + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glAlphaFunc( GL_GREATER, 0.95F ); + glEnable( GL_ALPHA_TEST ); + + glBindTexture( GL_TEXTURE_2D, texture ); + glBegin( GL_QUADS ); + + glTexCoord2f( 0.0, 0.0 ); + glVertex3f( x-x_size/2./xScale, y-y_size/2./yScale, 0.0 ); + + glTexCoord2f( 0.0, 1.0 ); + glVertex3f( x-x_size/2./xScale, y+y_size/2./yScale, 0.0 ); + + glTexCoord2f( 1.0, 1.0 ); + glVertex3f( x+x_size/2./xScale, y+y_size/2./yScale, 0.0 ); + + glTexCoord2f( 1.0, 0.0 ); + glVertex3f( x+x_size/2./xScale, y-y_size/2./yScale, 0.0 ); + + glEnd(); + glFlush(); + + glDisable( GL_ALPHA_TEST ); + glDisable( GL_TEXTURE_2D );*/ + drawTexturePart( texture, 1.0, 1.0, x_size, y_size, x, y ); +} + +//====================================================================== +// Function: drawTexture +// Purpose : +//======================================================================= +void GLViewer_Drawer::drawTexturePart( GLuint texture, + GLfloat x_ratio, + GLfloat y_ratio, + GLint x_size, + GLint y_size, + GLfloat x, + GLfloat y, + GLfloat scale ) +{ + float xScale = scale > 0. ? 1./scale : myXScale; + float yScale = scale > 0. ? 1./scale : myYScale; + + glColor4f( 1.0, 1.0, 1.0, 1.0 ); + + glEnable( GL_TEXTURE_2D ); + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glAlphaFunc( GL_GREATER, 0.95F ); + glEnable( GL_ALPHA_TEST ); + + glBindTexture( GL_TEXTURE_2D, texture ); + glBegin( GL_QUADS ); + + glTexCoord2f( 0.0, 0.0 ); + glVertex3f( x-x_size/2./xScale, y-y_size/2./yScale, 0.0 ); + + glTexCoord2f( 0.0, y_ratio ); + glVertex3f( x-x_size/2./xScale, y+y_size/2./yScale, 0.0 ); + + glTexCoord2f( x_ratio, y_ratio ); + glVertex3f( x+x_size/2./xScale, y+y_size/2./yScale, 0.0 ); + + glTexCoord2f( x_ratio, 0.0 ); + glVertex3f( x+x_size/2./xScale, y-y_size/2./yScale, 0.0 ); + + glEnd(); + glFlush(); + + glDisable( GL_ALPHA_TEST ); + glDisable( GL_TEXTURE_2D ); } //====================================================================== diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 86ba2a45f..253f5dd92 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -251,16 +251,64 @@ public: #endif //! Loads texture from file - static GLuint loadTexture( const QString& fileName ); + /*! + *\param fileName - the name of texture file + *\param x_size - the horizontal size of picture ( less or equal texture horizontal size ) + *\param y_size - the vertical size of picture ( less or equal texture vertical size ) + *\param t_size - the size of texture ( texture vertical size equals texture horizontal size ) + */ + static GLuint loadTexture( const QString& fileName, + GLint* x_size = 0, + GLint* y_size = 0, + GLint* t_size = 0); //! Draw square texture /*! *\param texture - the texture ID - *\param size - the size of texture + *\param size - the size of square texture + *\param x - x coord + *\param y - y coord + */ + void drawTexture( GLuint texture, + GLint size, + GLfloat x, + GLfloat y ); + + //! Draw texture + /*! + *\param texture - the texture ID + *\param x_size - the horizontal size of texture + *\param y_size - the vertical size of texture *\param x - x coord *\param y - y coord */ - void drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y ); + void drawTexture( GLuint texture, + GLint x_size, + GLint y_size, + GLfloat x, + GLfloat y ); + + //! Draw texture part + /*! + *\param texture - the texture ID + *\param x_ratio - the horizontal ratio of texture part + *\param y_ratio - the vertical ratio of texture part + *\param x_size - the horizontal size of texture + *\param y_size - the vertical size of texture + *\param x - x coord + *\param y - y coord + *\param scale - common scale factor ( if = 0, use drawer scales ) + */ + void drawTexturePart( GLuint texture, + GLfloat x_ratio, + GLfloat y_ratio, + GLint x_size, + GLint y_size, + GLfloat x, + GLfloat y, + GLfloat scale = 0 ); + + //! Draw text string /*! @@ -274,7 +322,7 @@ public: */ void drawText( const QString& text, GLfloat xPos, - GLfloat yPos, + GLfloat yPos, const QColor& color, QFont* aFont, int theSeparator, @@ -291,8 +339,8 @@ public: *\param smallFont - font format */ void drawGLText( QString text, - float x, - float y, + float x, + float y, int hPosition = GLText_Center, int vPosition = GLText_Center, QColor color = Qt::black, -- 2.39.2