OpenGL绘制图像.PIC库

OpenGL Draw Image. PIC Library

本文关键字:PIC 图像 绘制 OpenGL      更新时间:2023-10-16

我正试图在屏幕上画一幅图像。我正在使用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();
    }
}

我的最佳猜测是你的问题在这里:

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

glDrawPixels的最后一个参数需要是常量GLVoid*

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

但您正在传递一个内部