Set Primitive Color As Glcolor3F (R, G, B)
Set Primitive Color As Glcolor3F (R, G, B)
Set Primitive Color As Glcolor3F (R, G, B)
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0f,1.0f,0.0f); // Set PRIMITIVE color as
// glColor3f(R,G,B)
glPointSize(10.0);
glBegin(GL_POINTS);
glVertex2i(50, 200); //p1
glVertex2i(100, 100); //p2
glVertex2i(400, 100); //p3
glVertex2i(500, 200); //p4
glVertex2i(400, 300); //p5
glVertex2i(100, 300); //p6
glEnd();
glFlush(); // Process all OpenGL routines as quickly as
possible
}
void init()
{ // Set display window BACK GROUND color to as
glClearColor(R,G,B,Alpha)
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0.0, 500, 0.0, 500); // XMIN,XMAX YMIN
YMAX
}
OUTPUT
2) OpenGL Program to Print LINES on the Screen
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0f,1.0f,0.0f); // Set PRIMITIVE color as
// glColor3f(R,G,B)
glLineWidth(10.0);
glBegin(GL_LINES);
glVertex2i(50, 200); //p1
glVertex2i(100, 100); //p2
glVertex2i(400, 100); //p3
glVertex2i(500, 200); //p4
glVertex2i(400, 300); //p5
glVertex2i(100, 300); //p6
glEnd();
glFlush(); // Process all OpenGL routines as quickly as
possible
}
void init()
{ // Set display window BACK GROUND color to as
glClearColor(R,G,B,Alpha)
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0.0, 500, 0.0, 500); // XMIN,XMAX YMIN
YMAX
}
OUTPUT
3) OpenGL Program to Print LINES on the Screen using GL_LINE_STRIP
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0f,1.0f,0.0f); // Set PRIMITIVE color as
// glColor3f(R,G,B)
glLineWidth(10.0);
glBegin(GL_LINE_STRIP);
glVertex2i(50, 200); //p1
glVertex2i(100, 100); //p2
glVertex2i(400, 100); //p3
glVertex2i(500, 200); //p4
glVertex2i(400, 300); //p5
glVertex2i(100, 300); //p6
glEnd();
glFlush(); // Process all OpenGL routines as quickly as
possible
}
void init()
{ // Set display window BACK GROUND color to as
glClearColor(R,G,B,Alpha)
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0.0, 500, 0.0, 500); // XMIN,XMAX YMIN
YMAX
}
OUTPUT
4)OpenGL Program to Print LINES on the Screen using GL_LINE_LOOP
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0f,1.0f,0.0f); // Set PRIMITIVE color as
// glColor3f(R,G,B)
glLineWidth(10.0);
glBegin(GL_LINE_LOOP);
glVertex2i(50, 200); //p1
glVertex2i(100, 100); //p2
glVertex2i(400, 100); //p3
glVertex2i(500, 200); //p4
glVertex2i(400, 300); //p5
glVertex2i(100, 300); //p6
glEnd();
glFlush(); // Process all OpenGL routines as quickly as
possible
}
void init()
{ // Set display window BACK GROUND color to as
glClearColor(R,G,B,Alpha)
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0.0, 500, 0.0, 500); // XMIN,XMAX YMIN
YMAX
}
OUTPUT
6)OpenGL Program to Print LINES on the Screen using GL_TRIANGLES
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear display window
glColor3f(1.0f,1.0f,0.0f); // Set PRIMITIVE color as
// glColor3f(R,G,B)
glLineWidth(10.0);
glBegin(GL_TRIANGLES);
glVertex2i(50, 200); //p1
glVertex2i(100, 100); //p2
glVertex2i(400, 100); //p3
glVertex2i(500, 200); //p4
glVertex2i(400, 300); //p5
glVertex2i(100, 300); //p6
glEnd();
glFlush(); // Process all OpenGL routines as quickly as
possible
}
void init()
{ // Set display window BACK GROUND color to as
glClearColor(R,G,B,Alpha)
glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0.0, 500, 0.0, 500); // XMIN,XMAX YMIN
YMAX
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
OUTPUT
7)OPENGL PROGRAM TO CREATING A HOUSE
void init()
glMatrixMode(GL_PROJECTION);
void home()
//Roof
glBegin(GL_POLYGON);
glVertex2i(200, 500);
glVertex2i(600, 500);
glVertex2i(700, 350);
glVertex2i(300, 350);
glEnd();
glBegin(GL_TRIANGLES);
glVertex2i(200, 500);
glVertex2i(100, 350);
glVertex2i(300, 350);
glEnd();
// Front Wall
glBegin(GL_POLYGON);
glVertex2i(100, 350);
glVertex2i(300, 350);
glVertex2i(300, 100);
glVertex2i(100, 100);
glEnd();
// Front Door
glBegin(GL_POLYGON);
glVertex2i(150, 250);
glVertex2i(250, 250);
glVertex2i(250, 100);
glVertex2i(150, 100);
glEnd();
glPointSize(15);
glBegin(GL_POINTS);
glVertex2i(170, 170);
glEnd();
//side Wall
glBegin(GL_POLYGON);
glVertex2i(300, 350);
glVertex2i(700, 350);
glVertex2i(700, 100);
glVertex2i(300, 100);
glEnd();
// window one
glBegin(GL_POLYGON);
glVertex2i(330, 320);
glVertex2i(450, 320);
glVertex2i(450, 230);
glVertex2i(330, 230);
glEnd();
glLineWidth(5);
glBegin(GL_LINES);
glVertex2i(390, 320);
glVertex2i(390, 230);
glVertex2i(330, 273);
glVertex2i(450, 273);
glEnd();
// window two
glBegin(GL_POLYGON);
glVertex2i(530, 320);
glVertex2i(650, 320);
glVertex2i(650, 230);
glVertex2i(530, 230);
glEnd();
glLineWidth(5);
glBegin(GL_LINES);
glVertex2i(590, 320);
glVertex2i(590, 230);
glVertex2i(530, 273);
glVertex2i(650, 273);
glEnd();
// Entrance Path
glLineWidth(3);
glBegin(GL_POLYGON);
glVertex2i(150, 100);
glVertex2i(250, 100);
glVertex2i(210, 0);
glVertex2i(40, 0);
glEnd();
glFlush();
}
int main(int argc, char ** argv)
// Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 600);
init();
// Send graphics to display window
glutDisplayFunc(home);
glutMainLoop();
}
ASSIGNMENT PROBLEM