I want to make makePixel(...) function in C++ that can place a pixel in specified x and y. But I have no idea why my approach is not working.
#include "glut.h"
int WIDTH, HEIGHT = 400;
GLubyte* PixelBuffer = new GLubyte[WIDTH * HEIGHT * 3];
void display();
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(100, 100);
int MainWindow = glutCreateWindow("Hello Graphics!!");
glClearColor(0.5, 0.5, 0.5, 0);
makePixel(200,200,0,0,0,PixelBuffer);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, PixelBuffer);
glFlush();
}
In "glut.h"
void makePixel(int x, int y, int r, int g, int b, GLubyte* pixels)
{
if (0 <= x && x < window.width && 0 <= y && y < window.height) {
int position = (x + y * window.width) * 3;
pixels[position] = r;
pixels[position + 1] = g;
pixels[position + 2] = b;
}
}