• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Development with OpenGL and Qt
 

Development with OpenGL and Qt

on

  • 6,507 views

 

Statistics

Views

Total Views
6,507
Views on SlideShare
3,515
Embed Views
2,992

Actions

Likes
1
Downloads
0
Comments
0

6 Embeds 2,992

http://ronnyml.wordpress.com 2976
https://ronnyml.wordpress.com 5
http://translate.googleusercontent.com 5
http://webcache.googleusercontent.com 3
url_unknown 2
http://www.thesearchengine.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Development with OpenGL and Qt Development with OpenGL and Qt Presentation Transcript

    • 3D Development with Qt   
    • Agenda 3D Concepts OpenGL Qt + OpenGL   
    •    
    •    
    • We need an API   
    •   Graphics rendering API  
    • Current industry standard for 3D graphics  ( Hi DirectX! )     
    • MultiPlatform MultiLanguage Hardware Independent Open Standard   
    • More than 250 functions to produce  three­dimensional scenes glColor, glVertex, glTranslate, glRotate ...   
    • Geometric Primitives   
    •    
    • CameraPhysical locationsProjection properties    
    • LightingglEnable ( GL_LIGHTING )Lighting simulates how objects reflect lightMaterial compositionLight’s color and positionTwo sidedGLfloat mred[4]= {1,0,0,1};glMaterialfv(GL_FRONT, GL_AMBIENT, mred);    
    • Primitives are specified:glBegin(primitiveType);    …    …glEnd();Example:glBegin(GL_TRIANGLES);        glVertex3f( 0.0, 1.0, 0.0 );    glVertex3f( ­1.0, ­1.0, 0.0 );    glVertex3f( 1.0, ­1.0, 0.0 );glEnd();    
    • Color   
    • The human eye has 3 types of light receptor  cells glColor3f ( GLfloat red, GLfloat green, GLfloat blue );   
    • glBegin(GL_TRIANGLES);    // red    glColor3f( 1.0, 0.0, 0.0 );    glVertex3f( 0.0, 1.0, 0.0 );    // green    glColor3f( 0.0, 1.0, 0.0 );    glVertex3f( ­1.0, ­1.0, 0.0 );    // blue    glColor3f( 0.0, 0.0, 1.0 );    glVertex3f( 1.0, ­1.0, 0.0 );glEnd();      
    • ShadingSmooth:glShadeModel ( GL_SMOOTH  );    Flat:glShadeModel ( GL_FLAT  );      
    • // Smooth shadingglShadeModel(GL_SMOOTH); glBegin(GL_TRIANGLE_STRIP);        glColor3( 0.0, 0.5, 0.0 );        glVertex3( ­1.0, ­0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 1.0, ­0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 0.0, 0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 1.5, 0.0, ­5.0 );        glColor3( 0.0, 0.0, 1.0 );        glVertex3( 2.0, ­1.5, ­5.0 );          glEnd();
    • // Flat shadingglShadeModel(GL_FLAT); glBegin(GL_TRIANGLE_STRIP);        glColor3( 0.0, 0.5, 0.0 );        glVertex3( ­1.0, ­0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 1.0, ­0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 0.0, 0.5, ­5.0 );        glColor3( 1.0, 0.0, 0.0 );        glVertex3( 1.5, 0.0, ­5.0 );        glColor3( 0.0, 0.0, 1.0 );        glVertex3( 2.0, ­1.5, ­5.0 );          glEnd();
    •    glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );  
    •    
    • + Qt OpenGL module   
    • #include <QGLWidget>class GLWidget : public QGLWidget{    Q_OBJECTpublic:    GLWidget( QWidget *parent=0 );    ~GLWidget();    ...protected:    void initializeGL();    void resizeGL( int width, int height );    void paintGL();private:    ...   };
    •     void initializeGL();    void resizeGL( int width, int height );    void paintGL();    
    • void GLWidget::initializeGL() {     // Smooth shading     glShadeModel( GL_SMOOTH );      // Background color     glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );  ­>    qglClearColor( Qt::black );     // Depth buffer setup     glClearDepth( 1.0f );     // Enable depth testing     glEnable( GL_DEPTH_TEST );     // Set type of depth test     glDepthFunc( GL_LEQUAL );    }
    • void GLWidget::resizeGL( int width, int height )  {         if ( height == 0 )         height = 1;     // Reset current viewport     GlViewport( 0, 0, width, height );      // Select projection matrix     GlMatrixMode( GL_PROJECTION );           // Reset projection matrix     glLoadIdentity();      // Select modelview matrix     GlMatrixMode( GL_MODELVIEW );       // Reset modelview matrix       glLoadIdentity(); 
    • void GLWidget::paintGL() {     glClear ( GL_COLOR_BUFFER_BIT );     // Reset the drawing perspective     glLoadIdentity();      // triangle     glBegin (GL_TRIANGLES);         GlColor3f ( 1.0,  0.0,  0.0 );         glVertex3f ( 5.0,  5.0, 0.0 );         glColor3f ( 0.0,  1.0, 0.0 );         glVertex3f ( 25.0, 5.0, 0.0 );         glColor3f ( 0.0,  0.0, 1.0 );         GlVertex3f ( 5.0,  25.0, 0.0 );      glEnd();   }
    • void GLWidget::drawtriangle(){    glBegin ( GL_TRIANGLES );        glColor3f ( 1.0,  0.0,  0.0 );        glVertex3f ( 5.0,  5.0, 0.0 );           glColor3f ( 0.0,  1.0, 0.0 );        glVertex3f ( 25.0, 5.0, 0.0 );           glColor3f ( 0.0,  0.0, 1.0 );        glVertex3f ( 5.0,  25.0, 0.0 );    glEnd();}void GLWidget::paintGL(){    glClear ( GL_COLOR_BUFFER_BIT );    // Reset the drawing perspective    glLoadIdentity();         drawTriangle();
    • Demo Animation   
    • Demo Rotation   
    • Thanks Ronny Yabar Aizcorbe ronnycontacto@gmail.com ronnyml.wordpress.com