/
main.cpp
82 lines (60 loc) · 1.69 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <GL/glut.h>
#include "Planet.h"
#include "Sun.h"
// Window display size
GLsizei winWidth = 1280, winHeight = 1024;
// Initialize method
void init()
{
// Get and display your OpenGL version
std::cout << "Your OpenGL version is " << glGetString(GL_VERSION) << std::endl;
// Black background
glClearColor(0.0, 0.0, 0.0, 0.0);
// Projection on World Coordinates
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,(GLdouble) winWidth , 0.0,(GLdouble) winHeight);
}
// Draw method
void displayFcn()
{
int xc = winWidth / 2, yc = winHeight / 2;
float green[3] = {0.0, 0.75, 0.0};
float orange[3] = {1.0, 0.6, 0};
float red[3] = {1.0, 0.0, 0.0};
float blue[3] = {0.0, 0.0, 1.0};
// Clear display window.
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
Sun sun("Sun", xc, yc, 3.0);
glColor3fv(green);
Planet earth("Earth", xc, yc, 1.0, 1.0);
glColor3fv(orange);
Planet mercury("Mercury", xc, yc, 0.382, 0.39);
glColor3fv(blue);
Planet venus("Venus", xc, yc, 0.949, 0.72);
glColor3fv(red);
Planet mars("Mars", xc, yc, 0.532, 1.52);
glFlush( );
}
// Window redraw method
void winReshapeFcn(GLint newWidth, GLint newHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
gluOrtho2D(0.0,(GLdouble) newWidth, 0.0,(GLdouble) newHeight);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(winWidth, winHeight);
glutCreateWindow("Planets");
init();
glutDisplayFunc(displayFcn);
glutReshapeFunc(winReshapeFcn);
glutMainLoop();
return 0;
}