Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <glos.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <GL/glut.h>
- #include <gl/glaux.h>
- #include <conio.h>
- void CALLBACK display(void);
- void CALLBACK myReshape(GLsizei w, GLsizei h);
- double v;
- void CALLBACK display(void)
- {
- GLfloat materialEmission[] = { 0.1f,0.1f,0.1f, 0.8f };
- GLfloat materialColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat materialSpecular[] = { 0.1f,0.0f,0.1f,1.0f };
- GLfloat shininess = 150.0f;
- GLfloat no_materialEmission[] = { 0.0f,0.0f,0.0f, 1.0f };
- GLfloat no_materialColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- GLfloat no_materialSpecular[] = { 0.0f,0.0f,0.0f,1.0f };
- GLfloat no_shininess = 0.0f;
- GLfloat ambient[] = { 0.8f, 0.8f, 0.8f, 1.0f };
- GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat specular[] = { 0.8f, 0.5f, 0.5f, 1.0f };
- GLfloat position[] = { 0.0f, 200.0f, 200.0f, 0.0f };
- glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHTING);
- glEnable(GL_AUTO_NORMAL);
- glEnable(GL_NORMALIZE);
- glShadeModel(GL_FLAT);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- //pentru a fi desenat sistemul astfel încât obiectele din spate să fie acoperite de cele din faţă se va folosi următoarele doua functii
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
- glColor3f(1.0, 1.0, 1.0);
- glPushMatrix();
- /* Soare */
- glColor3d(1.0, 1.0, 0.0);
- glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColor);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, materialEmission);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); //The shininess parameter
- auxSolidSphere(0.8);
- /* Pamantul */
- glRotatef((GLfloat)v, 0.0, 1.0, 0.0);
- glTranslatef(2.2, 0.0, 0.0);
- glColor3d(0.0, 0.0, 1.0);
- glMaterialfv(GL_FRONT, GL_EMISSION, no_materialEmission);
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, no_materialColor);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, no_materialSpecular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_materialEmission);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, no_shininess); //The shininess parameter
- auxSolidSphere(0.3);
- /* Luna */
- glRotatef((GLfloat)v * 2, 0.0, 1.0, 0.0);
- glTranslatef(0.8, 0.0, 0.0);
- glMaterialfv(GL_FRONT, GL_EMISSION, no_materialEmission);
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, no_materialColor);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, no_materialSpecular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_materialEmission);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, no_shininess); //The shininess parameter
- glColor3d(0.5, 0.5, 0.5);
- auxSolidSphere(0.15);
- glPopMatrix();
- v++;
- glFlush();
- Sleep(30);
- }
- void CALLBACK myReshape(GLsizei w, GLsizei h)
- {
- if (!h) return;
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(40.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -5.0);
- }
- void main()
- {
- auxInitDisplayMode(AUX_SINGLE | AUX_RGB);
- auxInitPosition(0, 0, 800, 600);
- auxInitWindow("Sistem solar");
- auxIdleFunc(display);
- auxReshapeFunc(myReshape);
- auxMainLoop(display);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement