Question: Section 2 . 6 OpenGL Geometric PRIMITIVES ( a ) ( b ) Figure 2 . 3 2 : ( a ) Square annulus -

Section 2.6
OpenGL Geometric
PRIMITIVES
(a)
(b)
Figure 2.32: (a) Square
annulus - the region
between two bounding
squares - and a possible
triangulation (b) A
partially triangulated
shape. I want to generate these 2 diagrams in output using open gl. i have generated first diagram and its code is mentioned below. i want you to write a single program for generating both graphics. Here is code for first one.
//////////////////////////////////////////////////////////////////////
// squareAnnulus_modified.cpp
//
// This program draws a square annulus as a wireframe (only boundaries)
// using glVertex3f() for specifying vertices, confined to the upper
// middle half of the window.
//
// Sumanta Guha
//////////////////////////////////////////////////////////////////////
#include
#include
#include
// Drawing routine.
void drawScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// Draw outer square boundary.
glColor3f(0.0,0.0,0.0); // Set color to black.
glBegin(GL_LINE_LOOP);
glVertex3f(10.0,10.0,0.0); // Bottom left.
glVertex3f(10.0,90.0,0.0); // Top left.
glVertex3f(90.0,90.0,0.0); // Top right.
glVertex3f(90.0,10.0,0.0); // Bottom right.
glEnd();
// Draw inner square boundary.
glBegin(GL_LINE_LOOP);
glVertex3f(30.0,30.0,0.0); // Bottom left.
glVertex3f(30.0,70.0,0.0); // Top left.
glVertex3f(70.0,70.0,0.0); // Top right.
glVertex3f(70.0,30.0,0.0); // Bottom right.
glEnd();
// Draw square annulus triangles.
glBegin(GL_LINES);
// Bottom side.
glVertex3f(10.0,10.0,0.0);
glVertex3f(30.0,30.0,0.0);
glVertex3f(30.0,30.0,0.0);
glVertex3f(50.0,10.0,0.0);
glVertex3f(50.0,10.0,0.0);
glVertex3f(70.0,30.0,0.0);
// Left side.
glVertex3f(10.0,90.0,0.0);
glVertex3f(30.0,70.0,0.0);
glVertex3f(30.0,70.0,0.0);
glVertex3f(10.0,50.0,0.0);
glVertex3f(10.0,50.0,0.0);
glVertex3f(30.0,30.0,0.0);
// Top side.
glVertex3f(90.0,90.0,0.0);
glVertex3f(70.0,70.0,0.0);
glVertex3f(70.0,70.0,0.0);
glVertex3f(50.0,90.0,0.0);
glVertex3f(50.0,90.0,0.0);
glVertex3f(30.0,70.0,0.0);
// Right side.
glVertex3f(90.0,10.0,0.0);
glVertex3f(70.0,30.0,0.0);
glVertex3f(70.0,30.0,0.0);
glVertex3f(90.0,50.0,0.0);
glVertex3f(90.0,50.0,0.0);
glVertex3f(70.0,70.0,0.0);
glEnd();
glFlush();
}
// Initialization routine.
void setup(void)
{
glClearColor(1.0,1.0,1.0,0.0);
}
// OpenGL window reshape routine.
void resize(int w, int h)
{
glViewport(0, h /2, w /2, h /2); // Set viewport to upper middle half of the window.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,100.0,0.0,100.0,-1.0,1.0); // Orthographic projection.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// Main routine.
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitContextVersion(4,3);
glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("squareAnnulus_modified.cpp");
glutDisplayFunc(drawScene);
glutReshapeFunc(resize);
glewExperimental = GL_TRUE;
glewInit();
setup();
glutMainLoop();
return 0;
} REMEMBER, YOUR code should run properly in visual studio.
Section 2 . 6 OpenGL Geometric PRIMITIVES ( a ) (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!