This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 29th, 2012  |  syntax: C++  |  size: 4.09 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <Windows.h>
  2.  
  3. #include <gl/glew.h>
  4. #include <gl/glut.h>
  5.  
  6. #include <iostream>
  7.  
  8. static int wWidth = 800;
  9. static int wHeight = 600;
  10. static float yfov = 45.0f;
  11. static float zNear = 1.0f;
  12. static float zFar = 1600.0f;
  13.  
  14. static float red[] = {
  15.         0.63f,
  16.         0.06f,
  17.         0.04f,
  18.         1.0f
  19. };
  20.  
  21. static float green[] = {
  22.         0.15f,
  23.         0.48f,
  24.         0.09f,
  25.         1.0f
  26. };
  27.  
  28. static float white[] = {
  29.         0.76f,
  30.         0.75f,
  31.         0.5f,
  32.         1.0f
  33. };
  34.  
  35. using namespace std;
  36.  
  37. void SetupLights(void);
  38.  
  39. void ReshapeWindow(int width, int height);
  40. void Render(void);
  41.  
  42. int main(int argc, char *argv[])
  43. {
  44.  
  45.         glutInit(&argc, argv);
  46.         glewInit();
  47.  
  48.         glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE);
  49.         glutInitWindowSize(wWidth, wHeight);
  50.         glutInitWindowPosition(100, 100);
  51.  
  52.         glutCreateWindow("wtf?");
  53.  
  54.         glutReshapeFunc(ReshapeWindow);
  55.         glutDisplayFunc(Render);
  56.  
  57.         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  58.         glEnable(GL_CULL_FACE);
  59.         glCullFace(GL_BACK);
  60.        
  61.         SetupLights();
  62.  
  63.         glutMainLoop();
  64.  
  65.  
  66. }
  67.  
  68. void SetupLights(void)
  69. {
  70.  
  71.         glEnable(GL_LIGHTING);
  72.  
  73.         float lightPosition[] = {
  74.                 278.0f,
  75.                 425.0f,
  76.                 279.5f,
  77.                 0.0f
  78.         };
  79.  
  80.         float lightIntensity[] = {
  81.                 0.75f,
  82.                 0.75f,
  83.                 0.75f,
  84.                 1.0f
  85.         };
  86.  
  87.         float lightDirection[] = {
  88.                 0.0f,
  89.                 -1.0f,
  90.                 0.0f,
  91.                 0.0f // i think w component is not needed her but w/e
  92.         };
  93.  
  94.        
  95.  
  96.         glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
  97.         glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, lightIntensity);
  98.         glLightfv(GL_LIGHT0, GL_SPECULAR, lightIntensity);
  99.  
  100.         glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDirection);
  101.         //glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 170.0f);
  102.         //glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 128.0f);
  103.  
  104.         //glLighti(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1);
  105.         //glLighti(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1);
  106.         //glLighti(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1);
  107.  
  108.         glEnable(GL_LIGHT0);
  109.  
  110. }
  111.  
  112. void ReshapeWindow(int width, int height)
  113. {
  114.  
  115.         float ratio = (float) width / height;
  116.  
  117.         glMatrixMode(GL_PROJECTION);
  118.  
  119.         gluPerspective(yfov, ratio, zNear, zFar);
  120.         gluLookAt(278.0f, 273.0f, -800.0f, 278.0f, 273.0f, -799.0f, 0.0f, 1.0f, 0.0f);
  121.  
  122.         glMatrixMode(GL_MODELVIEW);
  123.  
  124. }
  125.  
  126. void Render(void)
  127. {
  128.  
  129.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  130.  
  131.        
  132.         glBegin(GL_TRIANGLES);
  133.                
  134.                 // CEILING
  135.  
  136.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  137.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  138.                
  139.                 glNormal3f(0.0f, -1.0f, 0.0f);
  140.  
  141.                 glVertex3f(556.0f, 548.8f, 0.0f);
  142.                 glVertex3f(556.0f, 548.0f, 592.2f);
  143.                 glVertex3f(0.0f, 548.8f, 0.0f);
  144.  
  145.                 glVertex3f(556.0f, 548.0f, 592.2f);
  146.                 glVertex3f(0.0f, 548.8f, 592.2f);
  147.                 glVertex3f(0.0f, 548.8f, 0.0f);
  148.  
  149.                 // FLOOR
  150.  
  151.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  152.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  153.  
  154.                 glNormal3f(0.0f, 1.0f, 0.0f);
  155.  
  156.                 glVertex3f(552.8, 0.0f, 0.0f);
  157.                 glVertex3f(0.0f, 0.0f, 0.0f);
  158.                 glVertex3f(549.6f, 0.0f, 592.2f);
  159.  
  160.                 glVertex3f(0.0f, 0.0f, 0.0f);
  161.                 glVertex3f(0.0f, 0.0f, 592.2f);
  162.                 glVertex3f(549.6f, 0.0f, 592.2f);
  163.  
  164.                 // BACK WALL
  165.  
  166.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  167.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  168.  
  169.                 glNormal3f(0.0f, 0.0f, -1.0f);
  170.  
  171.                 glVertex3f(549.6, 0.0f, 592.2f);
  172.                 glVertex3f(0.0f, 0.0f, 592.2f);
  173.                 glVertex3f(556.0f, 548.8f, 592.2f);
  174.  
  175.                 glVertex3f(0.0f, 0.0f, 592.2f);
  176.                 glVertex3f(0.0f, 548.8f, 592.2f);
  177.                 glVertex3f(556.0f, 548.8f, 592.2f);
  178.  
  179.                 // LEFT WALL
  180.  
  181.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  182.                 glMaterialfv(GL_FRONT, GL_SPECULAR, red);
  183.  
  184.                 glNormal3f(-1.0f, 0.0f, 0.0f);
  185.  
  186.                 glVertex3f(552.8f, 0.0f, 0.0f);
  187.                 glVertex3f(549.6f, 0.0f, 592.2f);
  188.                 glVertex3f(556.0f, 548.8f, 0.0f);
  189.  
  190.                 glVertex3f(549.6f, 0.0f, 592.2f);
  191.                 glVertex3f(556.0f, 548.8f, 592.2f);
  192.                 glVertex3f(556.0f, 548.8f, 0.0f);
  193.  
  194.                 // RIGHT WALL
  195.  
  196.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  197.                 glMaterialfv(GL_FRONT, GL_SPECULAR, green);
  198.  
  199.                 glNormal3f(1.0f, 0.0f, 0.0f);
  200.  
  201.                 glVertex3f(0.0f, 0.0f, 592.2f);
  202.                 glVertex3f(0.0f, 0.0f, 0.0f);
  203.                 glVertex3f(0.0f, 548.8f, 592.2f);
  204.  
  205.                 glVertex3f(0.0f, 0.0f, 0.0f);
  206.                 glVertex3f(0.0f, 548.8f, 0.0f);
  207.                 glVertex3f(0.0f, 548.8f, 592.2f);
  208.  
  209.         glEnd();
  210.        
  211.         glutSwapBuffers();
  212.  
  213. }
clone this paste RAW Paste Data