0% found this document useful (0 votes)
11 views4 pages

Department of Information & Technology University of Haripur, Haripur-Pakistan

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Department of Information & Technology University of Haripur, Haripur-Pakistan

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Information & Technology

University of Haripur, Haripur-Pakistan

CG

Submit to

Bilal Ahmad

Submitted by

Sameer Ahmad
F21-0308

Assignment Number: 01

Program: Computer Science

University of Haripur, Haripur-Pakistan


Drawing a Pixel on the Screen Using a C++ Graphics Library

#include <GL/glut.h>

int WIDTH = 400;


int HEIGHT = 400;
GLubyte* PixelBuffer = new GLubyte[WIDTH * HEIGHT * 3];

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;
}
}

int main(int argc, char *argv[])


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

1
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(100, 100);

int MainWindow = glutCreateWindow("Hello Graphics!!");


glClearColor(0.0, 0.0, 0.0, 0);

makePixel(200,200,255,255,255,PixelBuffer, WIDTH, HEIGHT);


glutDisplayFunc(display);
glutMainLoop();
return 0;

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.

You might also like