Subject: computer drawing OPENE GL GLUT . Hello, I want your help in writing comments on the lines of this code so that

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Subject: computer drawing OPENE GL GLUT . Hello, I want your help in writing comments on the lines of this code so that

Post by answerhappygod »

Subject: computer drawing OPENE GL GLUT .
Hello, I want your help in writing comments on the lines of this code so that it is easier for me to understand. Thank you for your cooperation with me .
#include <windows.h>#include <stdlib.h>#include <GL/glut.h>static int year1=0, day1=0, year2=0, day2=0;void init(void) { glClearColor(0.0,0.0,0.0,0.0); GLfloat mat_specular[]={1.0,1.0,1.0,1.0}; GLfloat mat_shininess[]={50.0}; GLfloat light_position0[]={1.0,1.0,1.0,0.0}; glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular); glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess); glLightfv(GL_LIGHT0,GL_POSITION,light_position0); GLfloat light_position1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; glLightfv(GL_LIGHT1, GL_POSITION, light_position1); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST);}void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glPushMatrix(); glutSolidSphere(1.0,20,16); glRotatef((GLfloat)year1,0.0,1.0,0.0); glTranslatef(2.0,0.0,0.0); glRotatef((GLfloat)day1,0.0,1.0,0.0); glutSolidSphere(0.2,10,8); glPopMatrix(); glPushMatrix(); glRotatef((GLfloat)year2,0.0,1.0,1.0); glTranslatef(2.0,1.0,0.0); glRotatef((GLfloat)day2,0.0,1.0,0.0); glutSolidSphere(0.2,10,8); glPopMatrix(); glutSwapBuffers();}void reshape(int w, int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0,(GLfloat)w/(GLfloat)h,1.0,20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0,0.0,8.0,0.0,0.0,0.0,0.0,1.0,0.0);}void keyboard(unsigned char key, int x, int y) { switch(key) { case 'd': day1=(day1+15)%360; glutPostRedisplay(); day2=(day2-10)%360; glutPostRedisplay(); break; case 'y': year1=(year1+10)%360; glutPostRedisplay(); year2=(year2-5)%360; glutPostRedisplay(); break; }}int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(600,600); glutInitWindowPosition(0,0); glutCreateWindow("UJIAN"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0;}
#include <windows.h>
#include <stdlib.h>
#include <GL/glut.h>
static int year1=0, day1=0, year2=0, day2=0;
void init(void) {
glClearColor(0.0,0.0,0.0,0.0);
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={50.0};
GLfloat light_position0[]={1.0,1.0,1.0,0.0};
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
GLfloat light_position1[] = {-1.0f, 0.5f, 0.5f, 0.0f};
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glutSolidSphere(1.0,20,16);
glRotatef((GLfloat)year1,0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat)day1,0.0,1.0,0.0);
glutSolidSphere(0.2,10,8);
glPopMatrix();
glPushMatrix();
glRotatef((GLfloat)year2,0.0,1.0,1.0);
glTranslatef(2.0,1.0,0.0);
glRotatef((GLfloat)day2,0.0,1.0,0.0);
glutSolidSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h) {
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0,(GLfloat)w/(GLfloat)h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,8.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
void keyboard(unsigned char key, int x, int y) {
switch(key) {
case 'd':
day1=(day1+15)%360; glutPostRedisplay();
day2=(day2-10)%360; glutPostRedisplay();
break;
case 'y':
year1=(year1+10)%360; glutPostRedisplay();
year2=(year2-5)%360; glutPostRedisplay();
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(600,600);
glutInitWindowPosition(0,0);
glutCreateWindow("UJIAN");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply