Department of Information & Technology University of Haripur, Haripur-Pakistan
Department of Information & Technology University of Haripur, Haripur-Pakistan
CG
Submit to
Bilal Ahmad
Submitted by
Sameer Ahmad
F21-0308
Assignment Number: 01
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, PixelBuffer);
glutSwapBuffers();
}
void makePixel(int x, int y, int r, int g, int b, GLubyte* pixels, int width, int height)
{
if (0 <= x && x < width && 0 <= y && y < height) {
int position = (x + y * width) * 3;
pixels[position] = r;
pixels[position + 1] = g;
pixels[position + 2] = b;
}
}
1
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(100, 100);
2
Summary:
This program showcases fundamental concepts in computer graphics using OpenGL and GLUT.
It demonstrates window initialization, pixel buffer creation, and RGB color manipulation. By
creating a white pixel on a black background, the code illustrates basic graphics rendering and
display.
This C++ program leverages OpenGL and GLUT to render a graphical window. It initializes a
400x400 window, sets the background color to black, and creates a pixel buffer to store image
data. The program utilizes the makePixel function to set RGB values for a specific pixel,
demonstrating basic graphics rendering.
To run this C++ code, specific hardware and software requirements must be met. On the
hardware side, a computer with a compatible operating system, a graphics card that supports
OpenGL, and a monitor with a minimum resolution of 400x400 pixels are necessary.