c++ - 动态 3D 阵列上的 OpenGL glDrawPixels

标签 c++ arrays opengl graphics

如何使用 OpenGL glDrawPixels() 绘制以下动态 3D 数组? 您可以在此处找到文档:http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/drawpixels.html

float ***array3d;

void InitScreenArray()
{
    int i, j;

    int screenX = scene.camera.vres;
    int screenY = scene.camera.hres;

    array3d = (float ***)malloc(sizeof(float **) * screenX);

    for (i = 0 ;  i < screenX; i++) {
        array3d[i] = (float **)malloc(sizeof(float *) * screenY);

        for (j = 0; j < screenY; j++)
          array3d[i][j] = (float *)malloc(sizeof(float) * /*Z_SIZE*/ 3);
    }
}

我只能使用以下头文件:

#include <math.h>
#include <stdlib.h>
#include <windows.h>     

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h> 

最佳答案

呃...由于您要使用单独的 malloc() 分配每个像素,因此您必须通过单独调用 来绘制每个像素>glDrawPixels(),也是。这(显然)很疯狂;位图图形的想法是像素以相邻的、紧凑的格式存储,因此可以快速 (O(1)) 从一个像素移动到另一个像素。这让我很困惑。

更明智的方法是通过一次调用分配“3D 数组”(通常称为 2D 像素数组,其中每个像素恰好由红色、绿色和蓝色分量组成)malloc(),像这样(在 C 中):

float *array3d;
array3d = malloc(scene.camera.hres * scene.camera.vres * 3 * sizeof *array3d);

关于c++ - 动态 3D 阵列上的 OpenGL glDrawPixels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/259890/

相关文章:

c++ - wxWidgets - wxMediaCtrl - 视频不播放

c++ - 复制构造函数和赋值运算符实现选择 -

c# - 如何在 C# 中移动数组的开头?

c# - 适用于 C#/Mono 的主动且完整的 OpenCL/GL 绑定(bind)

OpenGL + gtkglextmm + 林间空地

opengl - OpenGL中glClearDepth的用途是什么?

java - C++ 对 JNI 类型的引用,例如 jobject

C++ 静态计数器没有正确增加

javascript - 如何选择 Javascript 数组中的所有值?

javascript - csvtojson node.js(合并两个代码)