如何使用 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/