Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <gl/GL.h>
- #include <gl/GLU.h>
- #include <gl/glut.h>
- #include <iostream>
- using namespace std;
- #define WIDTH 640
- #define HEIGHT 480
- // starting camera position
- GLfloat eyeX=0.0;
- GLfloat eyeY=0.0;
- GLfloat eyeZ=2.0;
- GLfloat centerX=0.0;
- GLfloat centerY=0.0;
- GLfloat centerZ=0.0;
- GLfloat upX=0.0;
- GLfloat upY=1.0;
- GLfloat upZ=0.0;
- // aspect ratio
- GLdouble aspectRatio=WIDTH/HEIGHT;
- GLdouble worldx = 2.0*aspectRatio;
- GLdouble worldy = 2.0;
- // Zoom factor to allow the camera to 'zoom in' and 'zoom out'
- GLfloat zoomFactor = 1.0;
- // user defined functions
- void MyInit();
- void Draw();
- //void ChangeSize(GLsizei w, GLsizei h);
- //void SpecialKeys(int key, int x, int y);
- //void MyKeyboard(unsigned char theKey, int x, int y);
- //void myTimerFunction(int value);
- // Main function
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(WIDTH, 480);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Malignant Tumor Growth Model");
- glutDisplayFunc(Draw); // DisplayFunc callback is Draw
- //glutReshapeFunc(ChangeSize); // ReshapeFunc callback is ChangeSize
- //glutSpecialFunc(SpecialKeys); // SpecialFunc callback is SpecialKeys
- //glutKeyboardFunc(MyKeyboard); // KeyboardFunc callback is Keyboard
- glViewport(0, 0, 640, 480);
- //glutTimerFunc(1,myTimerFunction,0); // TimerFunc callback is myTimerFunction
- MyInit();
- glutMainLoop();
- return 0;
- }
- void MyInit()
- {
- glMatrixMode(GL_PROJECTION); // set the view volume shape
- glLoadIdentity();
- glOrtho(-worldx, worldx, -worldy, worldy, 0.1, 200);
- glMatrixMode(GL_MODELVIEW); // position and aim the camera
- glLoadIdentity();
- gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); // original view point
- glClearColor(1.0f, 0.5f, 0.5f, 0.0f);
- GLfloat mat_ambient[] = {0.0, 0.5, 0.8, 1.0 }; // object material settings
- GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0 };
- GLfloat mat_shininess[] = {50.0};
- GLfloat light_position0[] = {-1.0, 1.0, -2.0, 0.0 }; // light position
- GLfloat light_position1[] = {1.0, -1, -2.0, 0.0 };
- GLfloat light_position2[] = {1.0, -1.0, 2.0, 0.0 };
- GLfloat light_position3[] = {-1.0, -1.0, 2.0, 0.0 };
- GLfloat model_ambient[] = {0.5, 0.5, 0.5, 1.0 }; // lighting
- glClearColor(0.0, 0.0, 0.0, 0.0);
- // set lighting and material of the objects
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
- // set light 0
- glEnable(GL_LIGHTING);
- glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
- glEnable(GL_LIGHT0);
- // set light 1
- glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
- glEnable(GL_LIGHT1);
- // set light 2
- glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
- glEnable(GL_LIGHT2);
- // set light 3
- glLightfv(GL_LIGHT3, GL_POSITION, light_position3);
- glEnable(GL_LIGHT3);
- glEnable(GL_DEPTH_TEST);
- }
- // The purpose of this function is to draw the objects to the screen
- void Draw()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the screen
- glPushMatrix();
- glTranslated(-0.5, 0, 0);
- glutSolidTeapot(0.5);
- glPopMatrix();
- // draw cone at (1.65, 0, 0)
- glPushMatrix();
- glTranslated(1.65, 0,0.0);
- glutSolidCone(0.5, 1.5, 10, 8);
- glPopMatrix();
- glPopMatrix(); // restore the matrix state
- glutSwapBuffers();
- }
Add Comment
Please, Sign In to add comment