Lab 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Computer Graphics (SEng 4103)

Lab-5: Fill area Attributes in OpenGL


#include <GL/glut.h>
void myInit(void) {
glClearColor(1.0, 1.0,1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void display(void)
{
glColor3f(1.0, 0.0, 0.0); //Red color
//Draw only the edges of the polygons (wireframe rendering)
glPolygonMode (GL_FRONT, GL_LINE);
glBegin(GL_POLYGON);
glVertex2i(50, 250);
glVertex2i(100, 300);
glVertex2i(100, 340);
glVertex2i(10, 250);
glEnd( );
glColor3f(1.0, 1.0, 0.0); //Orange color
//fill the polygon faces
glPolygonMode (GL_FRONT, GL_FILL);
glBegin(GL_POLYGON);
glVertex2i(50, 150);
glVertex2i(100, 200);
glVertex2i(100, 240);
glVertex2i(10, 150);
glEnd( );
glColor3f(1.0, 0.0, 1.0); //Pink color
glPointSize(8);
//draw only the vertices of the polygons
glPolygonMode (GL_FRONT, GL_POINT);
glBegin(GL_POLYGON);
glVertex2i(50, 50);
glVertex2i(100, 100);
glVertex2i(100, 140);
glVertex2i(10, 50);
glEnd( );
Page-1
glPolygonMode (GL_FRONT, GL_FILL);
glColor3f(0.0, 1.0, 0.0); //Green color
GLubyte fillPattern [ ] =
{ 0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
0x00,0xFF };
//specify a fill pattern for polygons
glPolygonStipple(fillPattern);
glEnable(GL_POLYGON_STIPPLE);
glBegin(GL_POLYGON);
glVertex2i(350, 250);
glVertex2i(400, 300);
glVertex2i(400, 350);
glVertex2i(350, 400);
glVertex2i(300, 400);
glVertex2i(250, 350);
glVertex2i(250, 300);
glVertex2i(300, 250);
glEnd( );
glFlush( );
}
int main(int argc, char *argv[ ])
{
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutInitWindowPosition(10, 10);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("Fill Area attributes in OpenGL");
glutDisplayFunc(display);
myInit( );
glutMainLoop( );
}

Page-2

You might also like