├── 3D Solar System Scene using OpenGL.png ├── LICENSE ├── Makefile ├── Readme.md ├── game ├── game.cpp ├── game.o └── install-libraries.sh /3D Solar System Scene using OpenGL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HxnDev/3D-Solar-System-Scene-using-OpenGL/e042eb9850d9de6c22600636f597c3702345b9ae/3D Solar System Scene using OpenGL.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Hassan Shahzad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS = -O2 -g -Wall -fmessage-length=0 -Werror 2 | 3 | OBJS = game.o 4 | 5 | LIBS = -L/usr/X11R6/lib -L/sw/lib -L/usr/sww/lib -L/usr/sww/bin -L/usr/sww/pkg/Mesa/lib -lglut -lGLU -lGL -lX11 -lfreeimage 6 | 7 | 8 | 9 | TARGET = game 10 | 11 | 12 | $(TARGET): $(OBJS) 13 | $(CXX) -o $(TARGET) $(OBJS) $(LIBS) 14 | 15 | all: $(TARGET) 16 | 17 | clean: 18 | rm -f $(OBJS) $(TARGET) 19 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # 3D Solar System Scene 2 | This was my project from the sixth semester of course Computer Graphics. 3 | 4 | 5 | ## 1 Instructions 6 | 7 | ### 1.1 Installing libraries on Linux (Ubuntu) 8 | You can install libraries either from the Ubuntu software center or from command line. We recommend command line and provide the file “install-libraries.sh” to automate the complete installation procedure. To install libraries: 9 | 10 | 1. Simply run the terminal and go to directory which contains the file 11 | downloaded file “install-libraries.sh”. 12 | 13 | bash install-libraries.sh 14 | 15 | 2. Run the command 16 | 3. Provide the password and wait for the libraries to be installed. If you get an error that libglew1.6-dev cannot be found, try installing an older version, 17 | 18 | sudo apt-get install libglew1.5-dev 19 | such as libglew1.5-dev by issuing following on command line 20 | 21 | 4. If you have any other flavour of Linux. You can follow similar procedure to 22 | install “OpenGL” libraries. 23 | 24 | ### 1.2 Compiling and Executing 25 | To compile the game (skeleton) each time you will be using “g++”. However to automate the compilation and linking process we use a program “make”. Make takes as an input a file containing the names of files to compile and libraries to link. This file is named as “Makefile” in the game folder and contains the detail of all the libraries that game uses and need to linked. 26 | 27 | So each time you need to compile and link your program (game) you will be 28 | simply calling the “make” utility in the game directory on the terminal to perform 29 | make 30 | the compilation and linking. 31 | That’s it if there are no errors you will have your game executable (on running you will see three shapes on your screen). Otherwise try to remove the pointed syntax errors and repeat the make procedure. 32 | 33 | -------------------------------------------------------------------------------- /game: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HxnDev/3D-Solar-System-Scene-using-OpenGL/e042eb9850d9de6c22600636f597c3702345b9ae/game -------------------------------------------------------------------------------- /game.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Hassan Shahzad 3 | // 18i-0441 4 | // FAST-NUCES 5 | // Computer Graphics: 3D Solar System Scene 6 | // Contact at : chhxnshah@gmail.com 7 | //============================================================================ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | float xRotated = 90.0, yRotated = 0.0, zRotated = 0.0; 16 | 17 | //________________________________________________________________________________________________________________________________ 18 | 19 | //defining some MACROS 20 | 21 | #define FPS 1000 // frame per seconds 22 | 23 | // define another constant to hold ASCII for Escape key. 24 | #define KEY_ESC 27 25 | 26 | //________________________________________________________________________________________________________________________________ 27 | void reshapeFunc(int x, int y) 28 | { 29 | glMatrixMode(GL_PROJECTION); 30 | glLoadIdentity(); 31 | gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5,20.0); 32 | glMatrixMode(GL_MODELVIEW); 33 | glViewport(0,0,x,y); 34 | } 35 | //________________________________________________________________________________________________________________________________ 36 | 37 | 38 | void Draw_Spheres() 39 | { 40 | glClearColor(0/*Red Component*/, 0.0/*Green Component*/, 41 | 0.0/*Blue Component*/, 0 /*Alpha component*/); // Red==Green==Blue==1 --> White Colour 42 | glClear(GL_COLOR_BUFFER_BIT); //Update the colors 43 | glMatrixMode (GL_MODELVIEW); 44 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 45 | glLoadIdentity(); 46 | glTranslatef(0.0,0.0,-15.0); 47 | 48 | // SUN 49 | glColor4f(1.0,1.0,0.0,0.0); //Yellow color 50 | glPushMatrix(); 51 | glTranslatef(-12.5,0.0,0.0); 52 | glutSolidSphere(4.0,50,50); 53 | glPopMatrix(); 54 | 55 | // Mercury 56 | glColor3f(0.0,0.1,0.1); //Dark Grey color 57 | glPushMatrix(); 58 | glTranslatef(-7,0.0,0.0); 59 | glRotatef(60.0,1,0,0); 60 | glRotatef(zRotated*1.5,0,0,1); 61 | glutSolidSphere(0.4,15,10); 62 | glPopMatrix(); 63 | 64 | // Venus 65 | glColor4f(1.0,0.5,0.0,0.0); //Orange Brown color 66 | glPushMatrix(); 67 | glTranslatef(-5.5,0.0,0.0); 68 | glRotatef(60.0,1,0,0); 69 | glRotatef(zRotated,0,0,1); 70 | glutSolidSphere(0.7,20,20); 71 | glPopMatrix(); 72 | 73 | //Earth 74 | glColor3f(0.1,0.2,0.8); //Blue color 75 | glPushMatrix(); 76 | glTranslatef(-3.8,0.0,0.0); 77 | glRotatef(60.0,1,0,0); 78 | glRotatef(zRotated*3,0,0,1); 79 | glutSolidSphere(0.7,20,20); 80 | glPopMatrix(); 81 | 82 | //Mars 83 | glColor3f(0.8,0.2,0.1); //Red color 84 | glPushMatrix(); 85 | glTranslatef(-2.3,0.0,0.0); 86 | glRotatef(125.0,1,0,0); 87 | glRotatef(zRotated*4.0,0,0,1); 88 | glutSolidSphere(0.5,20,15); 89 | glPopMatrix(); 90 | 91 | //Jupiter 92 | glColor3f(1.0,0.5,0.0); //Orange color 93 | glPushMatrix(); 94 | glTranslatef(-0.5,0.0,0.0); 95 | glRotatef(125.0,1,0,0); 96 | glRotatef(zRotated*7.0,0,0,1); 97 | glutSolidSphere(1.0,20,40); 98 | glPopMatrix(); 99 | 100 | 101 | // Saturn 102 | glColor3f(0.0,0.5,0.5); //Bluish Green 103 | glPushMatrix(); 104 | glTranslatef(2.0,0.0,0.0); 105 | glRotatef(60.0,1,0,0); 106 | glRotatef(zRotated*6.5,0,0,1); 107 | glutSolidSphere(1.0,20,30); 108 | glPopMatrix(); 109 | 110 | //Uranus 111 | glColor3f(0.5,1.0,1.0); //Cyan Color, 112 | glPushMatrix(); 113 | glTranslatef(4.0,0.0,0.0); 114 | glRotatef(125.0,1,0,0); 115 | glRotatef(zRotated*5.0,0,0,1); 116 | glutSolidSphere(0.7,20,20); 117 | glPopMatrix(); 118 | 119 | 120 | //Neptune 121 | glColor3f(0.1,0.0,1.0); //Purple Color, 122 | glPushMatrix(); 123 | glTranslatef(6.0,0.0,0.0); 124 | glRotatef(60.0,1,0,0); 125 | glRotatef(zRotated*5.5,0,0,1); 126 | glutSolidSphere(0.7,20,20); 127 | glPopMatrix(); 128 | 129 | glutSwapBuffers(); 130 | } 131 | //________________________________________________________________________________________________________________________________ 132 | 133 | void idleFunc() 134 | { 135 | zRotated+=0.1; 136 | glutPostRedisplay(); 137 | } 138 | 139 | //________________________________________________________________________________________________________________________________ 140 | 141 | void SetCanvasSize(int width, int height) { 142 | glMatrixMode(GL_PROJECTION); 143 | glLoadIdentity(); 144 | glOrtho(0, width, 0, height, -1, 1); // set the screen size to given width and height. 145 | } 146 | //________________________________________________________________________________________________________________________________ 147 | 148 | void PrintableKeys(unsigned char key, int x, int y) { 149 | if (key == KEY_ESC/* Escape key ASCII*/) { 150 | exit(1); // exit the program when escape key is pressed. 151 | } 152 | } 153 | 154 | 155 | //________________________________________________________________________________________________________________________________ 156 | 157 | int main(int argc, char*argv[]) { 158 | int width = 1300, height = 800; // i have set my window size to be 800 x 600 159 | glutInit(&argc, argv); // initialize the graphics library... 160 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); // we will be using color display mode 161 | glutInitWindowPosition(50, 50); // set the initial position of our window 162 | glutInitWindowSize(width, height); // set the size of our window 163 | glutCreateWindow("Computer Graphics: 3D Solar System Scene"); // set the title of our game window 164 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 165 | SetCanvasSize(width, height); // set the number of pixels... 166 | glutDisplayFunc(Draw_Spheres); // tell library which function to call for drawing Canvas. 167 | glutReshapeFunc(reshapeFunc); 168 | glutIdleFunc(idleFunc); 169 | glutKeyboardFunc(PrintableKeys); // tell library which function to call for printable ASCII characters 170 | glutMainLoop(); 171 | return 1; 172 | } 173 | -------------------------------------------------------------------------------- /game.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HxnDev/3D-Solar-System-Scene-using-OpenGL/e042eb9850d9de6c22600636f597c3702345b9ae/game.o -------------------------------------------------------------------------------- /install-libraries.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt-get install freeglut3-dev glew-utils libglew1.6-dev libfreeimage-dev 3 | --------------------------------------------------------------------------------