2
私は、ウィンドウにピクセルを1ずつ描画する関数を持っています。赤以外の異なる色。前もって感謝します。 glSetColor、glColor3fなどのようなものをいくつか試しましたが、ピクセルをさまざまな色で表示しようとしましたが、これまでに何も動作していなかったようです。glDrawPixelsを使用しているときのピクセルの色を変更するにはどうすればいいですか?ピクセルは常に赤色です
#include <GL/glut.h>
#include <iostream>
using namespace std;
float *PixelBuffer;
void setPixel(int, int);
void display();
int size = 400 * 400 * 3;
int main(int argc, char *argv[])
{
PixelBuffer = new float[400 * 400 * 3];
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
glColor3f(0, 1.0, 0);
int firstWindow = glutCreateWindow("First Color");
glClearColor(0, 0, 0, 0); //clears the buffer of OpenGL
for(int i = 0; i < 20; i++)
{
setPixel(i, 10);
}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glDrawPixels(400, 400, GL_RGB, GL_FLOAT, PixelBuffer);
glFlush();
}
void setPixel(int x, int y)
{
int pixelLocation;
int width = 400;
pixLocation = (y * width * 3) + (x * 3);
PixelBuffer[pixelLocation] = 1;
};
ああ、私は「* 3」の部分なしでpixLocationを設定するとき、なぜそれは私にいくつかの奇妙な色を与えることがありますか?また、本当に速い応答に感謝します。 – Eldandor