Advertisement
Guest User

Untitled

a guest
May 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. // Rotation amounts
  2. static GLfloat xRot = 0.0f;
  3. static GLfloat yRot = 0.0f;
  4.  
  5. // Light values and coordinates
  6. GLfloat lightPos[] = { 0.0f, 3.0f, 0.0f, 1.0f };
  7. GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  8. GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  9. GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
  10. GLfloat spotDir[] = { 0.0f, 0.0f, -1.0f };
  11.  
  12. // put inside a function to use in the main game loop or just paste into the main game loop
  13. // First place the light
  14. // Save the coordinate transformation
  15. glPushMatrix();
  16. // Rotate coordinate system
  17. glRotatef(yRot, 0.0f, 1.0f, 0.0f);
  18. glRotatef(xRot, 1.0f, 0.0f, 0.0f);
  19.  
  20. // Specify new position and direction in rotated coords.
  21. glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  22. glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDir);
  23.  
  24. // Draw a red cone to enclose the light source
  25. glColor3f(1, 0, 0);
  26.  
  27. // Translate origin to move the cone out to where the light
  28. // is positioned.
  29. glTranslatef(lightPos[0], lightPos[1], lightPos[2]);
  30. //glutSolidCone(0.5f, 3.0f, 4, 4);
  31. GLUquadric *quad;
  32. quad = gluNewQuadric();
  33. gluSphere(quad, 0.5, 100, 20);
  34.  
  35.  
  36. // Draw a smaller displaced sphere to denote the light bulb
  37. // Save the lighting state variables
  38. glPushAttrib(GL_LIGHTING_BIT);
  39.  
  40. // Turn off lighting and specify a bright yellow sphere
  41. glDisable(GL_LIGHTING);
  42. glColor3ub(255, 255, 0);
  43. glRotated(180, 0, 0, 0);
  44. GLUquadricObj *theQuadric;
  45.  
  46. theQuadric = gluNewQuadric();
  47.  
  48. gluQuadricDrawStyle(theQuadric, GLU_FILL);
  49. gluQuadricNormals(theQuadric, GLU_SMOOTH);
  50. gluCylinder(theQuadric, 0.8, 0, 1, 100, 20);
  51.  
  52. gluDeleteQuadric(theQuadric);
  53. //glutSolidSphere(0.5f, 7.5, 7.5);
  54.  
  55. // Restore lighting state variables
  56. glPopAttrib();
  57.  
  58. // Restore coordinate transformations
  59. glPopMatrix();
  60.  
  61.  
  62. // Set material color and draw a sphere in the middle
  63. glColor3f(1, 1, 1);
  64.  
  65. glEnable(GL_DEPTH_TEST); // Hidden surface removal
  66. glFrontFace(GL_CCW); // Counter clock-wise polygons face out
  67. //glEnable(GL_CULL_FACE); // Do not try to display the back sides
  68.  
  69. // Enable lighting
  70. glEnable(GL_LIGHTING);
  71.  
  72. // Setup and enable light 0
  73. // Supply a slight ambient light so the objects can be seen
  74. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
  75.  
  76. // The light is composed of just a diffuse and specular components
  77. glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLight);
  78. glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
  79. glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  80.  
  81. // Specific spot effects
  82. // Cut off angle is 60 degrees
  83. glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 15.0f);
  84.  
  85. // Enable this light in particular
  86. glEnable(GL_LIGHT0);
  87.  
  88. // Enable color tracking
  89. glEnable(GL_COLOR_MATERIAL);
  90.  
  91. // Set Material properties to follow glColor values
  92. glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  93.  
  94. // All materials hereafter have full specular reflectivity
  95. // with a high shine
  96. glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
  97. glMateriali(GL_FRONT, GL_SHININESS, 128);
  98.  
  99. // Black background
  100. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement