Changeset 92

Show
Ignore:
Timestamp:
10/16/07 21:49:00 (1 year ago)
Author:
baxissimo
Message:

Got drawing of vertex colors working. Added two-sided lighting toggle and turned it on by default. A lot of models have inconsistent orientation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/OpenMeshD/OpenMesh/Apps/GLViewer/GLViewer.d

    r91 r92  
    221221        } 
    222222    } 
     223 
    223224    void mouse_down(ref SDL_MouseButtonEvent ev) 
    224225    { 
     
    233234        last_pos_[1] = ev.y; 
    234235    } 
     236 
    235237    void mouse_up(ref SDL_MouseButtonEvent ev) 
    236238    { 
     
    245247        last_pos_[1] = ev.y; 
    246248    } 
     249 
    247250    void mouse_move(ref SDL_MouseMotionEvent ev) 
    248251    { 
     
    413416                    g_app.drawer.flip_normals(); 
    414417                } 
     418                else if (key == SDLK_t) { 
     419                    g_app.drawer.two_sided_lighting = ! 
     420                        g_app.drawer.two_sided_lighting; 
     421                } 
    415422                else if (key == SDLK_PLUS || 
    416423                         key == SDLK_EQUALS) { 
  • trunk/OpenMeshD/OpenMesh/Apps/GLViewer/MeshDrawerT.d

    r88 r92  
    344344    void show_fnormals(bool fnorm) { show_fnormals_ = fnorm; } 
    345345    bool show_fnormals() { return show_fnormals_; } 
     346    void use_color(bool use_col) { use_color_ = use_color; } 
     347    bool use_color() { return use_color_; } 
    346348 
    347349    /// Set scaling for display of normal vectors 
     
    349351    /// Return current scaling for display of normal vectors 
    350352    float normal_scale() { return normal_scale_; } 
     353 
     354    /// Toggle two-sided lighting on and off.   
     355    /// Must be called when the GL context is active. 
     356    void two_sided_lighting(bool onOff) { 
     357        int ion = onOff; 
     358        glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &ion); 
     359    } 
     360 
     361    bool two_sided_lighting() { 
     362        GLboolean ion; 
     363        glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &ion); 
     364        return ion!=0; 
     365    } 
    351366 
    352367    void multviewGL() { 
     
    470485            glShadeModel(GL_SMOOTH); 
    471486            draw_openmesh(_draw_mode); 
     487 
    472488        } 
    473489 
     
    522538    void setDefaultMaterial() { 
    523539        GLfloat[] mat_a = [0.2, 0.2, 0.2, 1.0]; 
    524         GLfloat[] mat_d = [0.7, 0.7, 0.5, 1.0]; 
     540        GLfloat[] mat_d = [0.85, 0.85, 0.7, 1.0]; 
    525541        GLfloat[] mat_s = [0.6, 0.6, 0.4, 1.0]; 
    526542        GLfloat[] shine = [120.0]; 
     
    535551    { 
    536552        static GLfloat[4] pos1 = [0.1,  0.1,  0.08, 0.0]; // main light 
    537         static GLfloat[4] col1 = [ 0.9,  0.9,  0.7,  1.0]; // reddish 
     553        static GLfloat[4] col1 = [ 0.7,  0.7,  0.5,  1.0]; // reddish 
    538554 
    539555        static GLfloat[4] pos2 = [-0.1, -0.1, 0.05, 0.0]; // secondary 
    540         static GLfloat[4] col2 = [ 0.5,  0.6,  0.6,  1.0]; // bluish 
     556        static GLfloat[4] col2 = [ 0.4,  0.5,  0.55,  1.0]; // bluish 
    541557 
    542558        static GLfloat[4] pos3 = [ 0.0,  0.03,  0.1,  0.0]; // headlight 
     
    595611            view_all(); 
    596612        } 
     613 
     614        // Setup which material properties will track color, 
     615        // but don't enable GL_COLOR_MATERIAL by default 
     616        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 
     617 
     618        // Two sided lighting by default because lots of real 
     619        // models have inconsistent triangle ordering 
     620        int is_ON = 1; 
     621        glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE, &is_ON); 
    597622    } 
    598623 
     
    701726            glNormalPointer(GL_FLOAT, 0, mesh_.vertex_normals().ptr); 
    702727 
     728            if ( mesh_.has_vertex_colors()  && use_color_) 
     729            { 
     730                glEnable(GL_COLOR_MATERIAL); 
     731                glEnableClientState( GL_COLOR_ARRAY ); 
     732                glColorPointer(3, GL_UNSIGNED_BYTE, 0,mesh_.vertex_colors().ptr); 
     733            } 
     734 
    703735            if ( tex_id_ && mesh_.has_vertex_texcoords2D() ) 
    704736            { 
     
    724756            glDisableClientState(GL_VERTEX_ARRAY); 
    725757            glDisableClientState(GL_NORMAL_ARRAY); 
     758            glDisableClientState(GL_COLOR_ARRAY); 
     759            glDisable(GL_COLOR_MATERIAL); 
    726760 
    727761            if ( tex_id_ && mesh_.has_vertex_texcoords2D() ) 
     
    740774            glNormalPointer(GL_FLOAT, 0, mesh_.vertex_normals().ptr); 
    741775 
    742             if ( mesh_.has_vertex_colors() ) 
    743             { 
     776            if ( mesh_.has_vertex_colors() && use_color_ ) 
     777            { 
     778                glEnable(GL_COLOR_MATERIAL); 
    744779                glEnableClientState( GL_COLOR_ARRAY ); 
    745780                glColorPointer(3, GL_UNSIGNED_BYTE, 0,mesh_.vertex_colors().ptr); 
     
    761796            glDisableClientState(GL_NORMAL_ARRAY); 
    762797            glDisableClientState(GL_COLOR_ARRAY); 
     798            glDisable(GL_COLOR_MATERIAL); 
    763799        }   
    764800 
     
    826862            glNormalPointer(GL_FLOAT, 0, mesh_.vertex_normals().ptr); 
    827863 
     864 
     865            if (mesh_.has_vertex_colors() && use_color_) 
     866            { 
     867                glEnable(GL_COLOR_MATERIAL); 
     868                glEnableClientState(GL_COLOR_ARRAY); 
     869                glColorPointer(3, GL_UNSIGNED_BYTE, 0, mesh_.vertex_colors().ptr); 
     870            } 
     871 
    828872            if ( tex_id_ && mesh_.has_vertex_texcoords2D() ) 
    829873            { 
     
    848892            glDisableClientState(GL_NORMAL_ARRAY); 
    849893            glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
     894            glDisableClientState(GL_COLOR_ARRAY); 
     895            glDisable(GL_COLOR_MATERIAL); 
     896 
    850897        } 
    851898 
     
    892939            if (mesh_.has_vertex_colors() && use_color_) 
    893940            { 
     941                glEnable(GL_COLOR_MATERIAL); 
    894942                glEnableClientState(GL_COLOR_ARRAY); 
    895943                glColorPointer(3, GL_UNSIGNED_BYTE, 0, mesh_.vertex_colors().ptr); 
     944            } else { 
     945                glColor3f(1,1,1); 
    896946            } 
    897947 
     
    899949            glDisableClientState(GL_VERTEX_ARRAY); 
    900950            glDisableClientState(GL_COLOR_ARRAY); 
     951            glDisable(GL_COLOR_MATERIAL); 
    901952        } 
    902953