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: 3.99 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
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. };
  19.  
  20. static float green[] = {
  21.         0.15f,
  22.         0.48f,
  23.         0.09f
  24. };
  25.  
  26. static float white[] = {
  27.         0.76f,
  28.         0.75f,
  29.         0.5f
  30. };
  31.  
  32. using namespace std;
  33.  
  34. void SetupLights(void);
  35.  
  36. void ReshapeWindow(int width, int height);
  37. void Render(void);
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.  
  42.         glutInit(&argc, argv);
  43.         glewInit();
  44.  
  45.         glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE);
  46.         glutInitWindowSize(wWidth, wHeight);
  47.         glutInitWindowPosition(100, 100);
  48.  
  49.         glutCreateWindow("wtf?");
  50.  
  51.         glutReshapeFunc(ReshapeWindow);
  52.         glutDisplayFunc(Render);
  53.  
  54.         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  55.         glEnable(GL_CULL_FACE);
  56.         glCullFace(GL_BACK);
  57.        
  58.         SetupLights();
  59.  
  60.         glutMainLoop();
  61.  
  62.  
  63. }
  64.  
  65. void SetupLights(void)
  66. {
  67.  
  68.         glEnable(GL_LIGHTING);
  69.  
  70.         float lightPosition[] = {
  71.                 278.0f,
  72.                 274.4f,
  73.                 279.5f
  74.         };
  75.  
  76.         float lightIntensity[] = {
  77.                 0.75f,
  78.                 0.75f,
  79.                 0.75f
  80.         };
  81.  
  82.         float lightDirection[] = {
  83.                 0.0f,
  84.                 -1.0f,
  85.                 0.0f
  86.         };
  87.  
  88.        
  89.  
  90.         glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
  91.         glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, lightIntensity);
  92.         glLightfv(GL_LIGHT0, GL_SPECULAR, lightIntensity);
  93.  
  94.         //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDirection);
  95.         //glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 120.0f);
  96.         //glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 128.0f);
  97.  
  98.         //glLighti(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1);
  99.         //glLighti(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1);
  100.         //glLighti(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1);
  101.  
  102.         glEnable(GL_LIGHT0);
  103.  
  104. }
  105.  
  106. void ReshapeWindow(int width, int height)
  107. {
  108.  
  109.         float ratio = (float) width / height;
  110.  
  111.         glMatrixMode(GL_PROJECTION);
  112.  
  113.         gluPerspective(yfov, ratio, zNear, zFar);
  114.         gluLookAt(278.0f, 273.0f, -800.0f, 278.0f, 273.0f, -799.0f, 0.0f, 1.0f, 0.0f);
  115.  
  116.         glMatrixMode(GL_MODELVIEW);
  117.  
  118. }
  119.  
  120. void Render(void)
  121. {
  122.  
  123.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  124.  
  125.        
  126.         glBegin(GL_TRIANGLES);
  127.                
  128.                 // CEILING
  129.  
  130.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  131.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  132.                
  133.                 glNormal3f(0.0f, -1.0f, 0.0f);
  134.  
  135.                 glVertex3f(556.0f, 548.8f, 0.0f);
  136.                 glVertex3f(556.0f, 548.0f, 592.2f);
  137.                 glVertex3f(0.0f, 548.8f, 0.0f);
  138.  
  139.                 glVertex3f(556.0f, 548.0f, 592.2f);
  140.                 glVertex3f(0.0f, 548.8f, 592.2f);
  141.                 glVertex3f(0.0f, 548.8f, 0.0f);
  142.  
  143.                 // FLOOR
  144.  
  145.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  146.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  147.  
  148.                 glNormal3f(0.0f, 1.0f, 0.0f);
  149.  
  150.                 glVertex3f(552.8, 0.0f, 0.0f);
  151.                 glVertex3f(0.0f, 0.0f, 0.0f);
  152.                 glVertex3f(549.6f, 0.0f, 592.2f);
  153.  
  154.                 glVertex3f(0.0f, 0.0f, 0.0f);
  155.                 glVertex3f(0.0f, 0.0f, 592.2f);
  156.                 glVertex3f(549.6f, 0.0f, 592.2f);
  157.  
  158.                 // BACK WALL
  159.  
  160.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
  161.                 glMaterialfv(GL_FRONT, GL_SPECULAR, white);
  162.  
  163.                 glNormal3f(0.0f, 0.0f, -1.0f);
  164.  
  165.                 glVertex3f(549.6, 0.0f, 592.2f);
  166.                 glVertex3f(0.0f, 0.0f, 592.2f);
  167.                 glVertex3f(556.0f, 548.8f, 592.2f);
  168.  
  169.                 glVertex3f(0.0f, 0.0f, 592.2f);
  170.                 glVertex3f(0.0f, 548.8f, 592.2f);
  171.                 glVertex3f(556.0f, 548.8f, 592.2f);
  172.  
  173.                 // LEFT WALL
  174.  
  175.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  176.                 glMaterialfv(GL_FRONT, GL_SPECULAR, red);
  177.  
  178.                 glNormal3f(-1.0f, 0.0f, 0.0f);
  179.  
  180.                 glVertex3f(552.8f, 0.0f, 0.0f);
  181.                 glVertex3f(549.6f, 0.0f, 592.2f);
  182.                 glVertex3f(556.0f, 548.8f, 0.0f);
  183.  
  184.                 glVertex3f(549.6f, 0.0f, 592.2f);
  185.                 glVertex3f(556.0f, 548.8f, 592.2f);
  186.                 glVertex3f(556.0f, 548.8f, 0.0f);
  187.  
  188.                 // RIGHT WALL
  189.  
  190.                 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  191.                 glMaterialfv(GL_FRONT, GL_SPECULAR, green);
  192.  
  193.                 glNormal3f(1.0f, 0.0f, 0.0f);
  194.  
  195.                 glVertex3f(0.0f, 0.0f, 592.2f);
  196.                 glVertex3f(0.0f, 0.0f, 0.0f);
  197.                 glVertex3f(0.0f, 548.8f, 592.2f);
  198.  
  199.                 glVertex3f(0.0f, 0.0f, 0.0f);
  200.                 glVertex3f(0.0f, 548.8f, 0.0f);
  201.                 glVertex3f(0.0f, 548.8f, 592.2f);
  202.  
  203.         glEnd();
  204.        
  205.         glutSwapBuffers();
  206.  
  207. }
clone this paste RAW Paste Data