Ignore:
Timestamp:
03/06/07 14:26:14 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/main.cpp

    r2127 r2194  
    3737GLuint fb, depth_rb, color_tex; 
    3838 
     39#ifdef VERTEX_ARRAY_INTERLEAVE 
     40VertexIL *interleave = NULL; 
     41#endif 
     42 
     43GLuint vertex_buf = 0, 
     44       color_buf = 0; 
     45 
     46Vertex_ *buf_vertices = NULL; 
     47Color   *buf_colors = NULL; 
     48 
    3949int vmiWin = 0; 
    4050 
     
    4858void VMI::init(void) 
    4959{ 
    50     // Clear color 
    51     glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
    52      
    53     // Initialize viewing values 
    54     glMatrixMode(GL_PROJECTION); 
    55     glLoadIdentity(); 
    56     gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 
    57      
    58     //glPixelStorei(GL_PACK_ALIGNMENT, 1); 
    59     //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
    60      
    61     glShadeModel(GL_FLAT); 
    62      
    63     glDisable(GL_BLEND); 
    64  
    65     glEnable(GL_CULL_FACE); // important 
    66  
    67     glEnable(GL_DEPTH_TEST); 
    68  
    69     if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 
    70     { 
    71         fprintf(stderr,"GL_EXT_framebuffer_object extension is not available!\n"); 
    72         exit(1); 
    73     } else { 
    74          // create objects 
    75         glGenFramebuffersEXT(1, &fb);        // frame buffer 
    76         glGenTextures(1, &color_tex);        // texture 
    77         glGenRenderbuffersEXT(1, &depth_rb); // render buffer 
    78         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
    79  
    80         // initialize color texture 
    81         glBindTexture(GL_TEXTURE_2D, color_tex); 
    82         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 
    83                      GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
    84         // texture parameters 
    85         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    86         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
    87  
    88         // attach texture to framebuffer color buffer 
    89         glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
    90                                   GL_COLOR_ATTACHMENT0_EXT, 
    91                                   GL_TEXTURE_2D, color_tex, 0); 
    92         // initialize depth renderbuffer 
    93         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 
    94         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 
    95                                  GL_DEPTH_COMPONENT24, width, height); 
    96         // attach renderbuffer to framebuffer depth buffer 
    97         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 
    98                                      GL_DEPTH_ATTACHMENT_EXT, 
    99                                      GL_RENDERBUFFER_EXT, depth_rb); 
    100  
    101         // Check framebuffer completeness at the end of initialization. 
    102         CHECK_FRAMEBUFFER_STATUS(); 
    103     } 
    104     /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 
    105     { 
    106         fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 
    107     } 
    108     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 
    109     { 
    110         fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 
    111     } 
    112     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 
    113     { 
    114         fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 
    115     }*/ 
    116     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 
    117     { 
    118         fprintf(stderr,"GL_ARB_vertex_buffer_object extension is not available!\n"); 
    119     } else { 
     60        // Clear color 
     61        glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
     62 
     63        // Initialize viewing values 
     64        glMatrixMode(GL_PROJECTION); 
     65        glLoadIdentity(); 
     66        gluPerspective(fov, (GLdouble)width / height, 0.1, 40.0); 
     67 
     68        //glPixelStorei(GL_PACK_ALIGNMENT, 1); 
     69        //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     70 
     71        glShadeModel(GL_FLAT); 
     72 
     73        glDisable(GL_BLEND); 
     74 
     75        glEnable(GL_CULL_FACE); // important 
     76 
     77        glEnable(GL_DEPTH_TEST); 
     78 
     79        if (GL_TRUE != glewIsSupported((const char*) "GL_EXT_framebuffer_object")) 
     80        { 
     81                fprintf(stderr, 
     82                                                "GL_EXT_framebuffer_object extension is not available!\n"); 
     83                exit(1); 
     84        } 
     85        else 
     86        { 
     87                // create objects 
     88                glGenFramebuffersEXT(1, &fb);        // frame buffer 
     89                glGenTextures(1, &color_tex);        // texture 
     90                glGenRenderbuffersEXT(1, &depth_rb); // render buffer 
     91                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); 
     92 
     93                // initialize color texture 
     94                glBindTexture(GL_TEXTURE_2D, color_tex); 
     95                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, 
     96                                GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
     97                // texture parameters 
     98                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     99                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     100 
     101                // attach texture to framebuffer color buffer 
     102                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 
     103                                GL_COLOR_ATTACHMENT0_EXT, 
     104                                GL_TEXTURE_2D, color_tex, 0); 
     105                // initialize depth renderbuffer 
     106                glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb); 
     107                glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 
     108                                GL_DEPTH_COMPONENT24, width, height); 
     109                // attach renderbuffer to framebuffer depth buffer 
     110                glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 
     111                                GL_DEPTH_ATTACHMENT_EXT, 
     112                                GL_RENDERBUFFER_EXT, depth_rb); 
     113 
     114                // Check framebuffer completeness at the end of initialization. 
     115                CHECK_FRAMEBUFFER_STATUS(); 
     116        } 
     117        /*if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_fragment_shader")) 
     118                { 
     119                fprintf(stderr,"GL_ARB_fragment_shader extension is not available!\n"); 
     120                } 
     121                if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_shader")) 
     122                { 
     123                fprintf(stderr,"GL_ARB_vertex_shader extension is not available!\n"); 
     124                } 
     125                if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_shader_objects")) 
     126                { 
     127                fprintf(stderr,"GL_ARB_shader_objects extension is not available!\n"); 
     128                }*/ 
     129        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_vertex_buffer_object")) 
     130        { 
     131                fprintf(stderr, 
     132                                "GL_ARB_vertex_buffer_object extension is not available!\n"); 
     133        } 
     134        else 
     135        { 
    120136#ifdef VERTEX_BUFFER_OBJECTS 
    121          
    122         glGenBuffersARB(1, &vertex_buf); 
    123          
    124         glGenBuffersARB(1, &color_buf); 
    125 #endif 
    126     } 
    127     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 
    128     { 
    129         fprintf(stderr,"GL_ARB_occlusion_query extension is not available!\n"); 
    130     } else { 
     137                glGenBuffersARB(1, &vertex_buf); 
     138 
     139                glGenBuffersARB(1, &color_buf); 
     140#endif 
     141        } 
     142 
     143        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_occlusion_query")) 
     144        { 
     145                fprintf(stderr, 
     146                                "GL_ARB_occlusion_query extension is not available!\n"); 
     147        } 
     148        else 
     149        { 
    131150#ifdef USE_OCCLUSION_QUERY 
    132         // Generate a list of occlusion queries 
    133         queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 
    134         glGenQueriesARB(mesh->currentNumTriangles, queries);y 
    135 #endif 
    136     } 
    137     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 
    138     { 
    139         fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 
    140     } 
    141     if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 
    142     { 
    143         fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 
    144     } 
     151                // Generate a list of occlusion queries 
     152                queries = (GLuint *)malloc(mesh->currentNumTriangles * sizeof(GLuint)); 
     153                glGenQueriesARB(mesh->currentNumTriangles, queries); 
     154#endif 
     155        } 
     156 
     157        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_imaging")) 
     158        { 
     159                fprintf(stderr,"GL_ARB_imaging extension is not available!\n"); 
     160        } 
     161 
     162        if (GL_TRUE != glewIsSupported((const char*) "GL_ARB_multitexture")) 
     163        { 
     164                fprintf(stderr,"GL_ARB_multitexture extension is not available!\n"); 
     165        } 
     166 
    145167#ifdef _WIN32 
    146     if (GL_TRUE != wglewIsSupported((const char*) "WGL_EXT_swap_control")) 
    147     { 
    148         fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 
    149     } 
    150 #endif 
    151      
    152     // Allocate memory for the image pixels 
    153     pixels = (GLubyte *)malloc(width * height * 4 * sizeof(GLubyte)); 
    154      
    155     // Allocate memory for colors 
    156     colors = initColors(mesh->currentNumTriangles); 
    157  
    158     // Set a different color for every triangle  
    159     setColors4(colors, mesh->currentNumTriangles); 
     168        if (GL_TRUE != wglewIsSupported((const char*) "WGL_EXT_swap_control")) 
     169        { 
     170                fprintf(stderr,"WGL_EXT_swap_control extension is not available!\n"); 
     171        } 
     172#endif 
     173 
     174        // Allocate memory for the image pixels. 
     175        pixels = (GLubyte *)malloc(width * height * 4 * sizeof(GLubyte)); 
     176 
     177        // Allocate memory for colors. 
     178        colors = initColors(mesh->currentNumTriangles); 
     179 
     180        // Set a different color for every triangle. 
     181        setColors4(colors, mesh->currentNumTriangles); 
    160182} 
    161183 
     
    246268#endif 
    247269#ifdef VERTEX_ARRAY_INTERLEAVE 
    248     glInterleavedArrays (GL_T2F_C4UB_V3F, 0, intertwined); 
     270    glInterleavedArrays (GL_T2F_C4UB_V3F, 0, interleave); 
    249271    glDrawArrays(GL_TRIANGLES, 0, mesh->currentNumTriangles * 3); 
    250272#endif 
     
    444466#ifdef VERTEX_BUFFER_OBJECTS 
    445467    glDeleteBuffersARB(1, &vertex_buf); 
    446      
    447468    glDeleteBuffersARB(1, &color_buf); 
    448  
    449     //free(pbuf_vertices); 
    450     //free(pbuf_colors); 
    451469 
    452470                buf_vertices = NULL; 
     
    455473#endif 
    456474#ifdef VERTEX_ARRAY 
    457     //free(pbuf_vertices); 
    458     //free(pbuf_colors); 
     475    free(buf_vertices); 
     476    free(buf_colors); 
    459477 
    460478                buf_vertices = NULL; 
    461479    buf_colors = NULL; 
     480#endif 
     481#ifdef VERTEX_ARRAY_INTERLEAVE 
     482                free(interleave); 
     483                interleave = NULL; 
    462484#endif 
    463485 
Note: See TracChangeset for help on using the changeset viewer.