Coding Solution
Coding Solution
#include<iostream>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
using namespace std;
void display()
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0); // white
if (value == 1){
glColor3f(1.0, 0.0, 0.0); // red
}else if (value == 2){
glColor3f(0.0, 1.0, 0.0); // green
}
else if (value == 3){
glColor3f(1.0, 1.0, 0.0); // yellow
}
else if (value == 4){
glColor3f(0.0, 0.0, 1.0); // blue
}
else if (value == 5){
glColor3f(1.0, 0.0, 1.0); // magenta
}
else if (value == 6){
glColor3f(0.0, 1.0, 1.0); // cyan
}
/* draw scene */
glutSolidTeapot(0.5);
glutSwapBuffers();
}
void display1()
{
glClear(GL_COLOR_BUFFER_BIT);
if (value == 1){
translate[12] += 0.1;
glMultMatrixd(translate);
value = 0;
}
else if (value == 2){
translate[13] += 0.1;
glMultMatrixd(translate);
value = 0;
}
else if (value == 3){
glRotatef(20.0, 1.0, 0.0, 0.0);
value = 0;
}
else if (value == 4){
glScalef(0.1, 0.1, 0.1);
value = 0;
}
glColor3f(0.0, 1.0, 0.0);
glutWireTeapot(0.5);
glutSwapBuffers();
}
int main(int argc, char** argv){
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500); //Set the window size
glutInitWindowPosition(3, 5);
//Create the window
glutCreateWindow("Window1");
init();
createMenu();
glutDisplayFunc(display);
glutInitWindowPosition(530, 5);
glutCreateWindow("Window2");
Semester init();
1 - Year 4 15/10/2017
createMenu2();
glutDisplayFunc(display1);
glutMainLoop();
Royal University of Phnom Penh Subject: Computer Graphic 2
Faculty of Engineering Lecturer: Kor Sokchea
glutCreateWindow("Window2");
init();
createMenu2();
glutDisplayFunc(display1);
glutMainLoop();
return 0;