这是代码.输出是一个灰色的正方形 - 无论输入是什么,它显然是错误的.我的目标是能够将所有像素存储在某处并显示它们,以便我可以继续使用简单的光线跟踪器,而我似乎无法弄清楚这个glDrawPixels的事情.
#include <stdlib.h>
#include <GL/glut.h >
using namespace std;
struct RGBType {
float r;
float g;
float b;
//float a;
};
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RGBType *pixels = new RGBType[250*250];
for (int x = 0; x < 250; x++) {
for (int y = 0; y < 250; y++) {
pixels->r = 0;
pixels->g = 1;
pixels->b = 1;
//pixels->a = 200;
}
}
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,250,250,GL_RGB,GL_UNSIGNED_BYTE,pixels);
//glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0); …Run Code Online (Sandbox Code Playgroud)