I have a function that draws pixels 1 by 1 on a window, but what I want to know is how to get the pixels to be drawn in a different color other than red. Thanks in advance. I've tried some stuff like glSetColor, glColor3f, etc. Just to try and get the pixels to display in different colors but nothing seemed to work so far.
#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;
};