• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            關于OpenGl編程指南 第6版 第142頁 示例程序6-1 的運行問題

                    這個程序就編譯問題就花了我一個晚上的時間,很是郁悶,由于用的是 Visual Studio 2008,并且因為微軟對OpenGL的支持只到1.1,1.1以后微軟就不再支持了,為什么,因為微軟更想發展自家的DirectX。所以如果想使用OpenGL1.1以上的功能或者函數,只能使用OpenGL擴展,這些擴展是一些OpenGL團體或個人開發出來的能Windows上使用的OpenGL1.1以后的一些功能及函數。所以,在Windows上根本就沒有什么OpenGL2.0的頭文件或庫文件了,OpenGL1.1以后的東西都已經以擴展的形式存在了,而且,并沒有一個統一的標準。
                    網上關于這個解決的方法已經有很多,其中一個是用glew庫,glew也是一個擴展庫,包含了OpenGL中許多核心及擴展函數,可以到這里下載:   http://glew.sourceforge.net/                            
                   先安裝,再按下面順序包含頭文件(glew.h在glut.h前)
            #include <GL/glew.h>
            #include <GL/glut.h>
                  其中安裝了glew庫方法如下:
            bin/glew32.dll     to     %SystemRoot%/system32
            lib/glew32.lib     to     {VC Root}/Lib
            include/GL/glew.h     to     {VC Root}/Include/GL
            include/GL/wglew.h     to     {VC Root}/Include/GL


                  

             GLenum err = glewInit() ;     
             
            if (GLEW_OK != err)
             
            {
                 exit(
            -2);
             }


            上述都是簡單的問題,一直執行到這里的時候程序編譯是通過了,但是發現出現另外一個問題,那就是,當按下,a,s,r,m,x等鍵的時候完全沒有反應,于是我有查了一下,最后發現是由于沒有初始化glew的緣故,網上提供的通用方法是在init()函數調用之前先寫上如上幾行代碼:

            然后偶很郁悶的發現,編譯出現錯誤,這個地方也就是最神奇的地方,我試了很多次,都是提示錯誤,提示GLenum 標示符聲明不合法什么的,嘗試了一個晚上后終于放棄,過了幾天,重新回來看的時候,又試了幾次,做的都是換湯不換藥的事情,并將上述代碼的 exit(-2) 換成 return 0 ,還有就是把初始化的代碼換了個位置,放到init()函數的里面的開始部分,運行就OK了,不知道為什么出現這個問題,又換到以前的位置或是將 return 0 重新換回 exit(-2) 運行又是錯誤,鑒于這個問題的詭異性,相信大家或許沒遇到過,特此記錄下來,以供對后來可能會遇到的朋友們一個提示。也期待有哪位高人指點一下緣故?

             以下為最終運行成功的代碼:



            /**//*
               此程序有時成功有時失敗,只發現原因在于初始化glew的那幾句代碼的具體位置,具體緣由有待解決
            */
             

            /**//*
             *  blendeqn.c
             *  Demonstrate the different blending functions available with the
             *  OpenGL imaging subset.  This program demonstrates use of the
             *  glBlendEquation() call.
             *
             *  The following keys change the selected blend equation function:
             *
             *      'a'  ->  GL_FUNC_ADD
             *      's'  ->  GL_FUNC_SUBTRACT
             *      'r'  ->  GL_FUNC_REVERSE_SUBTRACT
             *      'm'  ->  GL_MIN
             *      'x'  ->  GL_MAX
             
            */



            #include 
            <GL/glew.h>
            #include 
            <GL/glut.h>
            #include 
            <stdlib.h>

            void init(void)
            {

               GLenum err 
            = glewInit() ;     
               
            if (GLEW_OK != err)return 0;
               
            /**//*上面兩行代碼很奇怪,加到主函數的init()函數前就不行,有時候又可以,此問題留待解決*/

               glClearColor(
            1.01.00.00.0);

               glBlendFunc(GL_ONE, GL_ONE);
               glEnable(GL_BLEND);
            }


            void display(void)
            {
               glClear(GL_COLOR_BUFFER_BIT);

               glColor3f(
            0.00.01.0);
               glRectf(
            -0.5,-0.5,0.5,0.5);

               glFlush();
            }


            void reshape(int w, int h)
            {
               GLdouble aspect 
            = (GLdouble) w / h;

               glViewport(
            00, (GLsizei) w, (GLsizei) h);
               glMatrixMode(GL_PROJECTION);
               glLoadIdentity();
               
            if (aspect < 1.0{
                 aspect 
            = 1.0 / aspect;
                 glOrtho(
            -aspect, aspect, -1.01.0-1.01.0);
               }
             else
                 glOrtho(
            -1.01.0-aspect, aspect, -1.01.0);
               glMatrixMode(GL_MODELVIEW);
            }


            void keyboard(unsigned char key, int x, int y)
            {
               
            switch (key) {
                  
            case 'a'case 'A':
                 
            /**//* Colors are added as: (1, 1, 0) + (0, 0, 1) = (1, 1, 1)
                  *  which will produce a white square on a yellow background.
                  
            */

                 glBlendEquation(GL_FUNC_ADD);
                 
            break;

                  
            case 's'case 'S':
                 
            /**//* Colors are subtracted as: (0, 0, 1) - (1, 1, 0) = (-1, -1, 1)
                  *  which is clamped to (0, 0, 1), producing a blue square on a
                  *  yellow background
                  
            */
                 glBlendEquation(GL_FUNC_SUBTRACT);
                 
            break;

                  
            case 'r'case 'R':
                 
            /**//* Colors are subtracted as: (1, 1, 0) - (0, 0, 1) = (1, 1, -1)
                  *  which is clamed to (1, 1, 0).  This produces yellow for both
                  *  the square and the background.
                  
            */

                 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
                 
            break;

                  
            case 'm'case 'M':
                 
            /**//* The minimum of each component is computed, as
                  *  [min(1, 0), min(1, 0), min(0, 1)] which equates to (0, 0, 0).
                  *  This will produce a black square on the yellow background.
                  
            */

                 glBlendEquation(GL_MIN);
                 
            break;

                  
            case 'x'case 'X':
                 
            /**//* The minimum of each component is computed, as
                  *  [max(1, 0), max(1, 0), max(0, 1)] which equates to (1, 1, 1)
                  *  This will produce a white square on the yellow background.
                  
            */

                 glBlendEquation(GL_MAX);
                 
            break;

                  
            case 27:
                     exit(
            0);
               }

               
               glutPostRedisplay();
            }


            int main(int argc, char** argv)

               glutInit(
            &argc, argv);
               glutInitDisplayMode(GLUT_SINGLE 
            | GLUT_RGB);
               glutInitWindowSize(
            512,512);
               glutInitWindowPosition(
            100100);
               glutCreateWindow(argv[
            0]);

               init();
               
               glutReshapeFunc(reshape);
               glutKeyboardFunc(keyboard);
               glutDisplayFunc(display);
               glutMainLoop();
               
            return 0;
            }



             

            posted on 2010-02-14 21:37 蝸牛也Coding 閱讀(1112) 評論(3)  編輯 收藏 引用

            評論

            # re: 關于OpenGl編程指南 第6版 第142頁 示例程序6-1 的運行問題 2010-02-27 15:53 philip

            太好了
            正為這個問題奇怪呢
            感謝感謝  回復  更多評論   

            # re: 關于OpenGl編程指南 第6版 第142頁 示例程序6-1 的運行問題 2011-04-28 10:18 susan

            Linking...
            blendeqn.obj : error LNK2001: unresolved external symbol __imp__glewInit
            blendeqn.obj : error LNK2001: unresolved external symbol __imp____glewBlendEquation
            Debug/blendeqn.exe : fatal error LNK1120: 2 unresolved externals
            執行 link.exe 時出錯.
            Creating browse info file...

            我按你說的改了,還是不行啊,為什么?  回復  更多評論   

            # re: 關于OpenGl編程指南 第6版 第142頁 示例程序6-1 的運行問題 2011-04-28 10:38 susan

            噢,想起來了,glew32.lib 在project setting 的links模塊下沒加上。  回復  更多評論   

            <2010年2月>
            31123456
            78910111213
            14151617181920
            21222324252627
            28123456
            78910111213

            導航

            統計

            常用鏈接

            留言簿(8)

            隨筆檔案(78)

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久国色AV免费看图片| 国产亚洲婷婷香蕉久久精品| 国产韩国精品一区二区三区久久 | 一级做a爰片久久毛片16| 91精品国产91久久久久久青草 | 久久久久精品国产亚洲AV无码| 久久精品国产99国产精品亚洲| 久久久一本精品99久久精品88| 精品久久综合1区2区3区激情| 久久Av无码精品人妻系列| 婷婷综合久久狠狠色99h| 久久精品国产亚洲αv忘忧草| 青青草原1769久久免费播放| 久久丫忘忧草产品| 午夜精品久久久久9999高清| 欧美一区二区精品久久| 成人久久免费网站| 久久成人小视频| 99久久99久久精品国产| 国产成人综合久久综合| 无码国产69精品久久久久网站| 久久综合亚洲色HEZYO社区| 国产午夜电影久久| 国产福利电影一区二区三区,免费久久久久久久精 | 久久久久久亚洲AV无码专区| 国产精品亚洲综合久久| 久久99热这里只有精品国产| 久久狠狠色狠狠色综合| 久久精品国产精品国产精品污| 色综合久久久久综合体桃花网 | 国产精品九九久久免费视频 | 狠狠色丁香婷婷综合久久来来去| 97久久精品午夜一区二区| 久久精品水蜜桃av综合天堂| 久久无码国产专区精品| 久久久精品久久久久影院| 精品久久久久久久久免费影院| 久久久久久久久久免免费精品| 国内精品久久久久久麻豆| 国产精品一区二区久久精品无码 | 亚洲国产精品久久久久婷婷老年|