RohamCsiga

Vik Wiki Grafika - Gömb

Jan 31st, 2014
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdlib.h>
  3.  
  4. #if defined(__APPLE__)
  5.   #include <OpenGL/gl.h>
  6.   #include <OpenGL/glu.h>
  7.   #include <GLUT/glut.h>
  8. #else
  9.   #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
  10.     #include <windows.h>
  11.   #endif
  12.   #include <GL/gl.h>
  13.   #include <GL/glu.h>
  14.   #include <GL/glut.h>
  15. #endif
  16.  
  17. void onDisplay() {
  18.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  19.  
  20.   glutSolidSphere(1.0f, 16, 16);
  21.  
  22.   glutSwapBuffers();
  23. }
  24.  
  25. void onIdle() {
  26.   static bool first_call = true;
  27.   if(first_call) {
  28.     glutPostRedisplay();
  29.     first_call = false;
  30.   }
  31. }
  32.  
  33. void onInitialization() {
  34.   glEnable(GL_DEPTH_TEST);
  35.   glMatrixMode(GL_PROJECTION);
  36.   gluPerspective(60, 1, 0.1, 10);
  37.   glMatrixMode(GL_MODELVIEW);
  38.   gluLookAt(-3, 2, -2, 0, 0, 0, 0, 1, 0);
  39.   glEnable(GL_LIGHTING);
  40.   glEnable(GL_COLOR_MATERIAL);
  41.   glEnable(GL_LIGHT0);
  42.   float p[4] = {-1.1f, 2.0f, -1.2f, 1};
  43.   glLightfv(GL_LIGHT0, GL_POSITION, p);
  44.   float c[4] = {0.7f, 0.8f, 0.9f, 1.0f};
  45.   glLightfv(GL_LIGHT0, GL_DIFFUSE, c);
  46.   glShadeModel(GL_SMOOTH);
  47.  
  48.   glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.0f);
  49.   glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5f);
  50.  
  51.   glFrontFace(GL_CCW);
  52.   glCullFace(GL_BACK);
  53.   glEnable(GL_CULL_FACE);
  54. }
  55.  
  56. void onKeyboard(unsigned char key, int, int) {}
  57.  
  58. void onKeyboardUp(unsigned char key, int, int) {}
  59.  
  60. void onMouse(int, int, int, int) {}
  61.  
  62. void onMouseMotion(int, int) {}
  63.  
  64. int main(int argc, char **argv) {
  65.   glutInit(&argc, argv);
  66.   glutInitWindowSize(300, 300);
  67.   glutInitWindowPosition(100, 100);
  68.   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  69.  
  70.   glutCreateWindow("Grafika pelda program");
  71.  
  72.   glMatrixMode(GL_MODELVIEW);
  73.   glLoadIdentity();
  74.   glMatrixMode(GL_PROJECTION);
  75.   glLoadIdentity();
  76.  
  77.   onInitialization();
  78.  
  79.   glutDisplayFunc(onDisplay);
  80.   glutMouseFunc(onMouse);
  81.   glutIdleFunc(onIdle);
  82.   glutKeyboardFunc(onKeyboard);
  83.   glutKeyboardUpFunc(onKeyboardUp);
  84.   glutMotionFunc(onMouseMotion);
  85.  
  86.   glutMainLoop();
  87.  
  88.   return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment