Question: In C++ 1. Get the Code CheckeredTriangles.cpp and execute: 2. Spin the triangles 360 degrees. 3. Add keyboard to make the spinning image to stop

In C++ 1. Get the Code CheckeredTriangles.cpp and execute:

2. Spin the triangles 360 degrees.

3. Add keyboard to make the spinning image to stop (p) and to start spinning (c).

4. Add keyboard to make the object go up (u) and down (d).

5. With keyboard, move the image left and right (keys: L: left, R: right).

6. With keyboard, add zoom in/zoom out (keys +: Zoom in, -: Zoom out).

CheckeredTriangles.cpp:

// This application is a trivial illustration of texture mapping. It draws

// several triangles, each with a texture mapped on to it. The same texture

// is used for each triangle, but the mappings vary quite a bit so it looks as

// if each triangle has a different texture.

#ifdef __APPLE_CC__

#include

#else

#include

#endif

#include

// Define a 2 x 2 red and yellow checkered pattern using RGB colors.

#define red {0xff, 0x00, 0x00}

#define yellow {0xff, 0xff, 0x00}

#define magenta {0xff, 0, 0xff}

GLubyte texture[][3] = {

red, yellow,

yellow, red,

};

// Fixes up camera and remaps texture when window reshaped.

void reshape(int width, int height) {

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(80, GLfloat(width)/height, 1, 40);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(2, -1, 5, 0, 0, 0, 0, 1, 0);

glEnable(GL_TEXTURE_2D);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexImage2D(GL_TEXTURE_2D,

0, // level 0

3, // use only R, G, and B components

2, 2, // texture has 2x2 texels

0, // no border

GL_RGB, // texels are in RGB format

GL_UNSIGNED_BYTE, // color components are unsigned bytes

texture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

}

// Draws three textured triangles. Each triangle uses the same texture,

// but the mappings of texture coordinates to vertex coordinates is

// different in each triangle.

void display() {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);

glTexCoord2f(0.5, 1.0); glVertex2f(-3, 3);

glTexCoord2f(0.0, 0.0); glVertex2f(-3, 0);

glTexCoord2f(1.0, 0.0); glVertex2f(0, 0);

glTexCoord2f(4, 8); glVertex2f(3, 3);

glTexCoord2f(0.0, 0.0); glVertex2f(0, 0);

glTexCoord2f(8, 0.0); glVertex2f(3, 0);

glTexCoord2f(5, 5); glVertex2f(0, 0);

glTexCoord2f(0.0, 0.0); glVertex2f(-1.5, -3);

glTexCoord2f(4, 0.0); glVertex2f(1.5, -3);

glEnd();

glFlush();

}

// Initializes GLUT and enters the main loop.

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(520, 390);

glutCreateWindow("Textured Triangles");

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutMainLoop();

}

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 Databases Questions!