{
public:
{
}
void initializeGL( )
{
glDisable( GL_LIGHTING );
glEnable( GL_TEXTURE_2D );
glViewport( 0, 0, width( ), height( ) );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
gluPerspective( 45.0f, (GLfloat)width( ) / (GLfloat)height( ), 0.1f, 100.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
texId = bindTexture( "test.png" );
}
void paintGL( ) override
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -6.0f );
//drawTexture( rect( ), texId);
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, 1.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, -1.0f, 0.0f );
//glColor3f( 0.0f, 1.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, -1.0f, 0.0f );
glEnd( );
}
private:
GLuint texId;
};
/*
* Application entry point.
*/
int main( int argc, char **argv )
{
window->setFixedSize( 800, 600 );
window
->setWindowTitle
( QString::fromUtf8( "test" ) );
Foo* foo = new Foo( centralWidget );
layout->addWidget( foo );
window->setCentralWidget( centralWidget );
window->show( );
return app.exec( );
}
class Foo : public QGLWidget
{
public:
Foo( QWidget* parent ) : QGLWidget( parent )
{
}
void initializeGL( )
{
glDisable( GL_LIGHTING );
glEnable( GL_TEXTURE_2D );
glViewport( 0, 0, width( ), height( ) );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
gluPerspective( 45.0f, (GLfloat)width( ) / (GLfloat)height( ), 0.1f, 100.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
texId = bindTexture( "test.png" );
}
void paintGL( ) override
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -6.0f );
//drawTexture( rect( ), texId);
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, 1.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, -1.0f, 0.0f );
//glColor3f( 0.0f, 1.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, -1.0f, 0.0f );
glEnd( );
}
private:
GLuint texId;
};
/*
* Application entry point.
*/
int main( int argc, char **argv )
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow( );
window->setFixedSize( 800, 600 );
window->setWindowTitle( QString::fromUtf8( "test" ) );
QWidget *centralWidget = new QWidget( window );
QVBoxLayout* layout = new QVBoxLayout( centralWidget );
Foo* foo = new Foo( centralWidget );
layout->addWidget( foo );
window->setCentralWidget( centralWidget );
window->show( );
return app.exec( );
}
To copy to clipboard, switch view to plain text mode
Bookmarks