Cg_lab1
Cg_lab1
Cg_lab1
Q1. A
CODE:
#include <GL/glut.h>
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Q1 B
CODE:
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0);
glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
glEnd();
glFlush();
}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Q1 C
CODE:
include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0);
glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
glEnd();
glFlush();
}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Q1. D
CODE:
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0);
glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
glEnd();
glFlush();
}
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Q2. A
CODE:
#include <GL/glut.h>
#include <string.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0); // Set background color to white
glColor3f(0.0, 0.0, 0.0); // Set drawing color to black
glMatrixMode(GL_PROJECTION); // Switch to projection matrix
glLoadIdentity(); // Reset the projection matrix
glOrtho(0.0, 400.0, 0.0, 400.0, -1.0, 1.0); // Set the orthographic projection
}
Q2 B
CODE:
#include <GL/glut.h>
#include <string.h>
// Display function for the first figure (Line segment between P1 and P2)
void displayFigure1() {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
// Display function for the second figure (Letter "A" shape using 5 points)
void displayFigure2() {
glClear(GL_COLOR_BUFFER_BIT);
// Letter "A" shape using 5 points
glBegin(GL_LINES);
glVertex2f(50, 250); // P1
glVertex2f(75, 300); // P2
glVertex2f(75, 300); // P2
glVertex2f(100, 250); // P3
glVertex2f(62.5, 275); // P4
glVertex2f(87.5, 275); // P5
glEnd();
drawText(48, 240, "P1");
drawText(73, 310, "P2");
drawText(98, 240, "P3");
drawText(60, 265, "P4");
drawText(85, 265, "P5");
glFlush();
}
// Display function for the third figure (Star shape using 6 points)
void displayFigure3() {
glClear(GL_COLOR_BUFFER_BIT);
glVertex2f(225, 300); // P2
glVertex2f(250, 250); // P3
glVertex2f(250, 250); // P3
glVertex2f(200, 275); // P4
glVertex2f(200, 275); // P4
glVertex2f(250, 275); // P5
glVertex2f(250, 275); // P5
glVertex2f(200, 250); // P6
glEnd();
drawText(198, 240, "P1");
drawText(223, 310, "P2");
drawText(248, 240, "P3");
drawText(198, 265, "P4");
drawText(248, 265, "P5");
drawText(198, 240, "P6");
glFlush();
}
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0); // Set background color to white
glColor3f(0.0, 0.0, 0.0); // Set drawing color to black
glMatrixMode(GL_PROJECTION); // Switch to projection matrix
glLoadIdentity(); // Reset the projection matrix
glOrtho(0.0, 400.0, 0.0, 400.0, -1.0, 1.0); // Set the orthographic projection
}
glutMainLoop();
return 0;
}
Q2 C
CODE:
#include <GL/glut.h>
#include <string.h>
glFlush();
}
glFlush();
}
glFlush();
}
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0); // Set background color to white
glColor3f(0.0, 0.0, 0.0); // Set drawing color to black
glMatrixMode(GL_PROJECTION); // Switch to projection matrix
glLoadIdentity(); // Reset the projection matrix
glutMainLoop();
return 0;
}