Question

In: Computer Science

OpenGL problem Draw the entire scene composed with more than 5 objects. Scene should Include rigid...

OpenGL problem

Draw the entire scene composed with more than 5 objects. Scene should Include rigid transformations such as scale, rotate, translate, etc.

And please write down the code of the application program.cpp file (files containing main, render, etc). Also, show the picture of captured result screen.

you should give 1. code of the application program.cpp, 2. picture of captured result screen(entire scene). Please don't give incomplete answer.

Solutions

Expert Solution

//To draw a simple shaded scene consisting of a tea pot on a table.
#include<GL/glut.h>
void displaySolid(void){
    glClearColor(0.5,0.5,0.1,0.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-100,100,-100,100,-100,100);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
//set properties of the surface material
    GLfloat mat_ambient[]={0.0f,1.0f,1.0f,1.0f};
    GLfloat mat_diffuse[]={1.0f,0.5f,1.0f,1.0f};
    GLfloat mat_specular[]={0.5f,0.5f,1.0f,1.0f};
    GLfloat mat_shininess[]={25.0f};
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);


//set the light source properties
    GLfloat lightIntensity[]={1.0f,0.7f,0.7f,1.0f};
    GLfloat light_position[]={25.0f,50.0f,50.0f,1.0f};
    glLightfv(GL_LIGHT0, GL_POSITION,light_position);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);

    glPushMatrix();
    glTranslated(0,30,0);
    glRotatef(35,1,0.5,0);
//glScaled(1,8,1);
    glutSolidTeapot(10);
//glutWireTeapot(10);
    glPopMatrix();

    GLfloat mat_ambient1[]={1.0f,0.0f,0.0f,1.0f};
    GLfloat mat_diffuse1[]={1.0f,1.0f,0.0f,1.0f};
    GLfloat mat_specular1[]={1.0f,1.0f,0.5f,1.0f};
    GLfloat mat_shininess1[]={25.0f};
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient1);
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse1);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular1);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess1);

//set the light source properties
    GLfloat lightIntensity1[]={0.5f,0.5f,0.5f,1.0f};
    GLfloat light_position1[]={25.0f,50.0f,50.0f,1.0f};
    glLightfv(GL_LIGHT0, GL_POSITION,light_position1);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity1);
//top surface
    glPushMatrix();
    glTranslated(0,20,0);
    glRotatef(-80,1,0.5,0.8);
//glRotatef(,0,0,1);
    glScalef(1.5,1.5,0.1);
    glutSolidCube(50);
    glPopMatrix();

//First Leg
    glPushMatrix();
    glTranslated(-45,-10,-5);
    glRotatef(45,0,1,0);
    glScalef(0.4,5.5,0.4);
    glutSolidCube(10);
    glPopMatrix();

//Second Leg
    glPushMatrix();
    glTranslated(-10,-25,5);
    glRotatef(45,0,1,0);
    glScalef(0.4,4.5,0.4);
    glutSolidCube(10);
    glPopMatrix();

//Third Leg
    glPushMatrix();
    glTranslated(45,-5,-10);
    glRotatef(45,0,1,0);
    glScaled(0.4,5.5,0.4);
    glutSolidCube(10);
    glPopMatrix();

//Fourth Leg
    glPushMatrix();
    glTranslated(10,5,-35);
    glRotatef(45,0,1,0);
    glScalef(0.4,6,0.4);
    glutSolidCube(10);
    glPopMatrix();

    glFlush();
}


int main(int argc, char *argv[]){
    glutInit(&argc,argv);
    glutInitWindowSize(600,600);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
    glutInitWindowPosition(10,10);
    glutInitWindowSize(500,500);
    glutCreateWindow("Simple shaded scene consisting of a tea pot on a table");
    glutDisplayFunc(displaySolid);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glutMainLoop();
}

OUTPUT :


Related Solutions

it appears more and more ceramic and metal objects are being replaced nowadays. These include :...
it appears more and more ceramic and metal objects are being replaced nowadays. These include : 1) household materials (some ceramic bath tubs or floors are replaced with polymer materials ) 2) metal pipes surrounding the house/ building become plastic pipes 3) even our lunch boxes nowdays are made of plastics instead of metal . list one advantage for using polymers but not ceramic/ metals in each of the above mentioned 3 cases and the cited polymer advantage in each...
can you please write a good descriptive fight scene in a classroom this should include person...
can you please write a good descriptive fight scene in a classroom this should include person vs person make sure this scene is well written
Create a word problem to model a real life senario.It should be more difficult than counting...
Create a word problem to model a real life senario.It should be more difficult than counting change.
"General Accounting Principles" Please respond to the following: Should accounting include more than monetary units? Throughout...
"General Accounting Principles" Please respond to the following: Should accounting include more than monetary units? Throughout your textbook additional insights into how companies are attempting to meet the challenge of measuring and reporting their contributions to society, as well as their financial results, to stockholders are referenced. Discuss why a company's stockholders might be interested in its environmental and social performance. Next, determine the critical pieces of information companies are providing and why this information is important from the perspective...
Should accounting include more than monetary units? Throughout your textbook additional insights into how companies are...
Should accounting include more than monetary units? Throughout your textbook additional insights into how companies are attempting to meet the challenge of measuring and reporting their contributions to society, as well as their financial results, to stockholders are referenced. Discuss why a company's stockholders might be interested in its environmental and social performance. Next, determine the critical pieces of information companies are providing and why this information is important from the perspective of the different stakeholders.
Engineering an entire photosynthetic pathway is more complicated than simply inserting a gene for, say, an...
Engineering an entire photosynthetic pathway is more complicated than simply inserting a gene for, say, an insecticidal protein into the genome of a crop. How does the fact that C4 photosynthesis has evolved naturally many times in the grass family (which includes rice) suggest that it may be possible to introduce this trait to rice
A small juvenile gang composed of no more than 15 members has been active in the...
A small juvenile gang composed of no more than 15 members has been active in the community recently. Their members have been linked to drug sales, assaults, thefts and graffiti. The gang is multiracial and appears to be led by a slightly older person, who is about 20 years of age. What approach would you take to reduce or eliminate these gang problems?
Main task is solving problem, in this code there is problem. and you should explain? #include...
Main task is solving problem, in this code there is problem. and you should explain? #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1], O_RDONLY)) == -1) || ((fd2 = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0700)) == -1)){ perror("file problem "); exit(1); } while((n1=read(fd1, buffer, 512) > 0)) if(write(fd2, buffer, n1) != n1){ perror("writing problem "); exit(3); } // Case of an error exit from the loop if(n1 ==...
A publisher is interested in the effects on sales of college texts that include more than...
A publisher is interested in the effects on sales of college texts that include more than 100 data files. The publisher plans to produce 20 texts in the business area and randomly choses 10 to have more than 100 data files. The remaining 10 are produced with at most 100 data files. For those with more than 100, first-year sales averaged 9254, and the sample standard deviation was 2107. For the books with at most 100, average first-year sales were...
What is involute? Draw an involute with string length more than the cicumference of the corresponding...
What is involute? Draw an involute with string length more than the cicumference of the corresponding circle
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT