2013-02-18 80 views
0

我想在屏幕上繪製圖像。我正在使用PIC庫進行圖像處理。OpenGL繪製圖像。 PIC庫

現在,我有像素強度的數組,每個值看起來像這樣

currentImage->pix[currentRow * x * bytesPerPixel] = number from 0 to 256. 

我想用這樣的畫出來的圖像:

// initialize the most basic image 
for (int y = currentImage->ny; y >= 0; y--) { 

    // draw out each row of pixels 
      // line 18 -- this following line throws the error on compile 
      glReadPixels(0, 479-y, 640, 1, GL_RGB, GL_UNSIGNED_BYTE, &image->pix[y*image->nx*image->bpp]); 

} 

但這不起作用。當我嘗試編譯時,我不斷收到此錯誤:

g++ -O3 -I/usr/local/src/pic -Iinclude -o current src/main.cpp src/modules/*.cpp -L/usr/local/src/pic -framework OpenGL -framework GLUT -lpicio -ljpeg 
src/modules/application.cpp: In function ‘void application::idle()’: 
src/modules/application.cpp:18: error: invalid conversion from ‘int’ to ‘const GLvoid*’ 
make: *** [all] Error 1 

有沒有人有過類似的問題?我只是試圖在屏幕上畫出最基本的圖像,現在開始。

這是我的main.cpp函數,用於初始化gl顯示函數。

// set up the main display function 
    glutDisplayFunc(application::display); 

    // set the various callbacks for the interaction with opengl 
    glutIdleFunc(application::display); 

Application.cpp完整的文件:

namespace application { 

    void init() { 


     idle();  
    } 

    // implement idle function -- responsible for working with the image on a consistent basis to continually ensure its integrity 
    void idle() { 

     // initialize the most basic image 
     for (int y = currentImage->ny; y >= 0; y--) { 

      // draw out each row of pixels 
      glDrawPixels(currentImage->nx, 1, GL_RGBA, GL_UNSIGNED_BYTE, currentImage->pix[y * currentImage->nx * currentImage->bpp]); 
     } 

    } 


    // display is for drawing out the elements using our scaled frame etc 
    void display() { 

     // rotate, scaling and translation should take place before this code in the future 
     // draw a quick cube around the origin of the screen 
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     glClearColor(000.0, 0.0, 0.0, 1.0); 
     glutSwapBuffers(); 

    } 

} 
+1

'application.cpp'在第18行左右有什麼? – congusbongus 2013-02-18 23:49:29

+0

這是一個孤立的功能。我初始化我的程序並在此函數之前繪製背景等。 – JonMorehouse 2013-02-18 23:51:43

+0

它正在停止您的程序編譯。你可以向我們展示application.cpp,或者至少第18行的一部分。 – 2013-02-18 23:54:28

回答

1

我最好的猜測是你的問題就在這裏:

glDrawPixels(currentImage->nx, 1, GL_RGBA, GL_UNSIGNED_BYTE, currentImage->pix[y * currentImage->nx * currentImage->bpp]); 

glDrawPixels的最後一個參數必須是const GLVoid *

http://www.opengl.org/sdk/docs/man2/xhtml/glDrawPixels.xml

但你傳遞給它一個int。

+0

任何想法如何將整數轉換爲適當的值?我正在查看該圖紙的鏈接和其他文檔,看起來似乎沒有任何進展 – JonMorehouse 2013-02-19 00:04:16

+0

我從未實際使用過glReadPixels或glDrawPixels。但參數const GLVoid *是標籤數據。所以我猜測這應該是一個指向數據緩衝區的指針。所以嘗試傳遞它只是currentImage-> pix或者如果數據是在一個偏移量使用&currentImage-> pix [offsetAmount] – 2013-02-19 01:48:37