CG Lab2
CG Lab2
Q1.(A)
CODE:
#include <GL/glut.h>
#include <cmath> // for sin and cos
return 0;
}
Q1(B)
CODE:
#include <GL/glut.h>
#include <cmath>
glBegin(GL_LINE_LOOP);
for (int i = 0; i < numSegments; ++i) {
float angle = 2.0f * 3.1415926f * float(i) / float(numSegments); // Compute angle
float x = radius * cosf(angle) + centerX; // x coordinate
float y = radius * sinf(angle) + centerY; // y coordinate
glVertex2f(x, y);
}
glEnd();
}
void display() {
// Clear the window with the current clear color
glClear(GL_COLOR_BUFFER_BIT);
// Draw the second circle with radius 50 and center at (20, 20)
drawCircle(50.0f, 20.0f, 20.0f);
void init() {
// Set the clear color to black
glClearColor(0.0, 0.0, 0.0, 0.0);
return 0;
}
Q2. DDA A
CODE:
#include <GL/glut.h>
#include <cmath>
void displayWindow();
void ddaLine(float x1, float y1, float x2, float y2);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDA Line Algorithm - 512x512");
glutDisplayFunc(displayWindow);
glutMainLoop();
return 0;
}
float x = x1;
float y = y1;
glEnd();
}
void displayWindow() {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
Q2 DDA STAR
CODE:
#include <GL/glut.h>
#include <cmath>
void displayWindow();
void ddaLine(float x1, float y1, float x2, float y2);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDA Line Algorithm - 512x512");
glutDisplayFunc(displayWindow);
glutMainLoop();
return 0;
}
float x = x1;
float y = y1;
glEnd();
}
void displayWindow() {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
Q3. BRESHMAN A
CODE:
#include <GL/glut.h>
#include <cmath>
void displayWindow();
void ddaLine(float x1, float y1, float x2, float y2);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDA Line Algorithm - 512x512");
glutDisplayFunc(displayWindow);
glutMainLoop();
return 0;
}
float x = x1;
float y = y1;
glEnd();
}
void displayWindow() {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ddaLine(-100.0f, 0.0f, 100.0f, 0.0f);
ddaLine(0.0f, 173.0f, -100.0f, 0.0f);
ddaLine(0.0f, 173.0f, 100.0f, 0.0f);
ddaLine(100.0f, 100.0f, -100.0f, 100.0f);
ddaLine(0.0f, -73.0f, 100.0f, 100.0f);
ddaLine(0.0f, -73.0f, -100.0f, 100.0f);
glutSwapBuffers();
}
CODE:
#include <GL/glut.h>
#include <cmath>
void displayWindow();
void ddaLine(float x1, float y1, float x2, float y2);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDA Line Algorithm - 512x512");
glutDisplayFunc(displayWindow);
glutMainLoop();
return 0;
}
float x = x1;
float y = y1;
glEnd();
}
void displayWindow() {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);