0

我正在尝试在屏幕上绘制图像。我正在使用 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

以前有没有人遇到过类似的问题?我现在只是尝试在屏幕上绘制最基本的图像。

这是我初始化 gl 显示函数的 main.cpp 函数。

 // 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();

    }

}
4

1 回答 1

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。

于 2013-02-19T00:02:01.877 回答