Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program that allows you to modify the viewport. Create a project, build, and run the program. Use the arrow keys to make the viewport

This program that allows you to modify the viewport. Create a project, build, and run the program. Use the arrow keys to make the viewport smaller and the mouse to drag the viewport to a new location. Study the code to see how this is done.

As a demonstrates the use of the OpenGLviewport function, this program uses a split-screen effect to show two views of a triangle in the xy plane with its centroid at the world-coordinate origin. First a viewport is defined in the left half of the display window, and the original triangle is displayer there in a blue color. Using the same clipping window, another viewport is defined for the right half of the display window, and the fill color is changed to red. Create a project, build, and run the program to see the output of the program. Study the code to see how this is done.

use OpenGL dev-c++ , Please modify this code to show 16 views of a triangle, each with a different color. :

#ifdef __APPLE_CC__ #include #else #include #endif

//#include

class wcPt2D { public: GLfloat x, y; }; //------------------------------------------------------------------- void init() { // Set the color of display window to white glClearColor(1.0, 1.0, 1.0, 1.0);

// Set parameters for world-coordinate clipping window glMatrixMode(GL_PROJECTION); gluOrtho2D(-100.0, 100.0, -100.0, 100.0); } //------------------------------------------------------------------- void triangle (wcPt2D *verts) { GLint k;

glBegin(GL_TRIANGLES); for(k = 0; k < 3; k++) glVertex2f(verts[k].x, verts[k].y); glEnd(); } //------------------------------------------------------------------- void displayFcn() { // Define initial position for triangle wcPt2D verts[3] = { {-50.0, -25.0}, {50.0, -25.0}, {0.0, 50.0} }; glClear(GL_COLOR_BUFFER_BIT); // Clear the display window

// Display triangle in the left half of the window glColor3f(0.0, 0.0, 1.0); // Set the fill color to blue glViewport(0, 0, 300, 300); // Set left viewport triangle(verts); // Display the blue triangle

// Display triangle in the right half of the window glColor3f(1.0, 0.0, 0.0); // Set the fill color to red glViewport(300, 0, 300, 300); // Set right viewport triangle(verts); // Display the red triangle

glFlush(); } //------------------------------------------------------------------- int main( int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutInitWindowPosition(50, 50); glutInitWindowSize(600, 300); glutCreateWindow("Split-Screen Example"); init(); glutDisplayFunc(displayFcn); glutMainLoop(); } //-------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain illusory correlations.

Answered: 1 week ago

Question

Describe the key parts of the technology design step.

Answered: 1 week ago