OpenGL绘图图像。 PIC库

时间:2013-02-18 23:46:31

标签: c++ c opengl glut

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

答案 0 :(得分: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。