Advertisement
Ladies_Man

eafhgsdfgs

May 19th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.36 KB | None | 0 0
  1. // glfw_30.cpp : Defines the entry point for the console application.
  2. //  http://www.glfw.org/docs/latest/quick.html
  3. #include "stdafx.h"
  4. #define _CRT_SECURE_NO_DEPRECATE
  5. #include <time.h>
  6. #define _USE_MATH_DEFINES
  7. #include <cmath>
  8. #include <GL/glew.h>
  9. #include <GLFW/glfw3.h>
  10. #include <vector>
  11. #include <Windows.h>
  12. #include <GL/glut.h>
  13. #include <GL/GL.h>
  14.  
  15. #define SCREEN_WIDTH 1000
  16. #define SCREEN_HEIGHT 1000
  17. #define PC_MODE 16
  18. #define CONSOLE_MODE 0
  19.  
  20. #define MAXRAD 4
  21. #define MINRAD 1
  22. #define MAXHEIGHT 7
  23. #define MINHEIGHT 1
  24. #define MAXFREQ_X 40
  25. #define MINFREQ_X 3
  26. #define ANGLE 2
  27.  
  28. typedef struct {
  29.     GLfloat x, y, z;
  30. } coord;
  31.  
  32. std::vector<std::vector<coord>> cone_top;
  33. std::vector<std::vector<coord>> cone_bot;
  34. std::vector<std::vector<coord>> cone_side;
  35.  
  36. std::vector<std::vector<coord>> cyl_top;
  37. std::vector<std::vector<coord>> cyl_bot;
  38. std::vector<std::vector<coord>> cyl_side;
  39.  
  40. bool twinkie_flag, tex_flag, light_flag;
  41. int type, stop_i, stop_j, freq_x, freq_y;
  42. float t, twinkie_steps = 100, dt = 1 / twinkie_steps;
  43.  
  44. static float alpha, beta, gamma, h, r;
  45.  
  46. static GLuint texture;
  47.  
  48. static void error_callback(int error, const char* description)
  49. {
  50.     fputs(description, stderr);
  51. }
  52.  
  53. #define BITMAP_ID 0x4D42       
  54. BITMAPINFOHEADER    bitmapInfoHeader;   // temp bitmap info header
  55. BITMAPINFOHEADER    landInfo;           // land texture info header
  56.  
  57. unsigned char*        imageData;           // the map image data
  58. unsigned char*       landTexture;      // land texture data
  59.  
  60. unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
  61. {
  62.     FILE *filePtr;                                // the file pointer
  63.     BITMAPFILEHEADER    bitmapFileHeader;       // bitmap file header
  64.     unsigned char       *bitmapImage;           // bitmap image data
  65.     int                 imageIdx = 0;          // image index counter
  66.     unsigned char       tempRGB;                   // swap variable
  67.  
  68.     // open filename in "read binary" mode
  69.     filePtr = fopen(filename, "rb");
  70.     if (filePtr == NULL)
  71.         return NULL;
  72.  
  73.     // read the bitmap file header
  74.     fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
  75.  
  76.     // verify that this is a bitmap by checking for the universal bitmap id
  77.     if (bitmapFileHeader.bfType != BITMAP_ID)
  78.     {
  79.         fclose(filePtr);
  80.         return NULL;
  81.     }
  82.  
  83.     // read the bitmap information header
  84.     fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
  85.  
  86.     // move file pointer to beginning of bitmap data
  87.     fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
  88.  
  89.     // allocate enough memory for the bitmap image data
  90.     bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
  91.  
  92.     // verify memory allocation
  93.     if (!bitmapImage)
  94.     {
  95.         free(bitmapImage);
  96.         fclose(filePtr);
  97.         return NULL;
  98.     }
  99.  
  100.     // read in the bitmap image data
  101.     fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
  102.  
  103.     // make sure bitmap image data was read
  104.     if (bitmapImage == NULL)
  105.     {
  106.         fclose(filePtr);
  107.         return NULL;
  108.     }
  109.  
  110.     // swap the R and B values to get RGB since the bitmap color format is in BGR
  111.     for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3)
  112.     {
  113.         tempRGB = bitmapImage[imageIdx];
  114.         bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
  115.         bitmapImage[imageIdx + 2] = tempRGB;
  116.     }
  117.  
  118.     // close the file and return the bitmap image data
  119.     fclose(filePtr);
  120.     return bitmapImage;
  121. }
  122.  
  123. /*
  124. GLuint raw_texture_load(const char *filename, int width, int height)
  125. {
  126.     GLuint texture;
  127.     unsigned char *data;
  128.     FILE *file;
  129.  
  130.     // open texture data
  131.     file = fopen(filename, "rb");
  132.     if (file == NULL) return 0;
  133.  
  134.     // allocate buffer
  135.     data = (unsigned char*)malloc(width * height * 4);
  136.  
  137.     // read texture data
  138.     fread(data, width * height * 4, 1, file);
  139.     fclose(file);
  140.  
  141.     // allocate a texture name
  142.     glGenTextures(1, &texture);
  143.  
  144.     // select our current texture
  145.     glBindTexture(GL_TEXTURE_2D, texture);
  146.  
  147.     // select modulate to mix texture with color for shading
  148.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  149.  
  150.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
  151.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
  152.  
  153.     // when texture area is small, bilinear filter the closest mipmap
  154.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  155.     // when texture area is large, bilinear filter the first mipmap
  156.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  157.  
  158.     // texture should tile
  159.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  160.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  161.  
  162.     // build our texture mipmaps
  163.     gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
  164.  
  165.     // free buffer
  166.     free(data);
  167.  
  168.     return texture;
  169. }  */
  170.  
  171. void free_vect(std::vector<std::vector<coord>>& vect)
  172. {
  173.     for (int i = 0; i < freq_y + 1; i++) {
  174.         vect[i].clear();
  175.         vect[i].shrink_to_fit();
  176.     }
  177.     vect.clear();
  178.     vect.shrink_to_fit();
  179. }
  180.  
  181. void count_cylinder()
  182. {
  183.     int i, j, rad = r;
  184.     float angle, dangle, height, dheight, drad0;
  185.    
  186.  
  187.     height = h;
  188.     dheight = height / (float)freq_y;
  189.     dangle = 2 * M_PI / (float)freq_x;
  190.     drad0 = rad / (float)freq_y;
  191.  
  192.  
  193.  
  194.     cyl_top.resize(freq_y + 1);
  195.     for (i = 0; i < freq_y + 1; i++) cyl_top[i].resize(freq_x + 1);
  196.  
  197.     cyl_bot.resize(freq_y + 1);
  198.     for (i = 0; i < freq_y + 1; i++) cyl_bot[i].resize(freq_x + 1);
  199.  
  200.     cyl_side.resize(freq_y + 1);
  201.     for (i = 0; i < freq_y + 1; i++) cyl_side[i].resize(freq_x + 1);
  202.  
  203.  
  204.  
  205.     for (i = 0; i < freq_y + 1; i += 1) {
  206.         for (j = 0, angle = 0; angle <= 2 * M_PI + dangle; j += 1, angle += dangle) {
  207.             cyl_top[i][j].x = drad0 * i * cos(angle);
  208.             cyl_top[i][j].y = height;
  209.             cyl_top[i][j].z = drad0 * i * sin(angle);
  210.  
  211.             cyl_side[i][j].x = rad * cos(angle);
  212.             cyl_side[i][j].y = height - dheight * i;
  213.             cyl_side[i][j].z = rad * sin(angle);
  214.            
  215.             cyl_bot[i][j].x = drad0 * i * cos(angle);
  216.             cyl_bot[i][j].y = 0;
  217.             cyl_bot[i][j].z = drad0 * i * sin(angle);
  218.         }
  219.     }
  220.     stop_i = i;
  221.     stop_j = j;
  222.  
  223.     printf("cyl_renewed: h=%.2f, r=%d, fr_x=%d, fr_y=%d s_i=%d s_j=%d\n", height, rad, freq_x, freq_y, stop_i, stop_j);
  224. }
  225.  
  226. void count_cone()
  227. {
  228.     int i, j, top_rad = r, bot_rad = r * 2;
  229.     float angle, dangle, height, dheight, drad0, drad1, drad2;
  230.  
  231.  
  232.  
  233.     height = h;
  234.     dheight = height / (float)freq_y;
  235.     dangle = 2 * M_PI / (float)freq_x;
  236.     drad0 = top_rad / (float)freq_y;
  237.     drad1 = (bot_rad - top_rad) / (float)freq_y;
  238.     drad2 = bot_rad / (float)freq_y;
  239.  
  240.  
  241.  
  242.     cone_top.resize(freq_y + 1);
  243.     for (i = 0; i < freq_y + 1; i++) cone_top[i].resize(freq_x + 1);
  244.  
  245.     cone_bot.resize(freq_y + 1);
  246.     for (i = 0; i < freq_y + 1; i++) cone_bot[i].resize(freq_x + 1);
  247.  
  248.     cone_side.resize(freq_y + 1);
  249.     for (i = 0; i < freq_y + 1; i++) cone_side[i].resize(freq_x + 1);
  250.  
  251.  
  252.  
  253.     for (i = 0; i < freq_y + 1; i += 1) {
  254.         for (j = 0, angle = 0; angle <= 2 * M_PI + dangle; j += 1, angle += dangle) {
  255.             cone_top[i][j].x = drad0 * i * cos(angle);
  256.             cone_top[i][j].y = height;
  257.             cone_top[i][j].z = drad0 * i * sin(angle);
  258.  
  259.             cone_side[i][j].x = (top_rad + drad1 * i) * cos(angle);
  260.             cone_side[i][j].y = height - dheight * i;
  261.             cone_side[i][j].z = (top_rad + drad1 * i) * sin(angle);
  262.  
  263.             cone_bot[i][j].x = drad2 * i * cos(angle);
  264.             cone_bot[i][j].y = 0;
  265.             cone_bot[i][j].z = drad2 * i * sin(angle);
  266.         }
  267.     }
  268.     stop_i = i;
  269.     stop_j = j;
  270.  
  271.     printf("cone_renewed: h=%.2f, top_r=%d, fr_x=%d, fr_y=%d s_i=%d s_j=%d\n", height, top_rad, freq_x, freq_y, stop_i, stop_j);
  272. }
  273.  
  274. void draw_figure(
  275.     std::vector<std::vector<coord>>& top,
  276.     std::vector<std::vector<coord>>& side,
  277.     std::vector<std::vector<coord>>& bot
  278.     )
  279. {
  280.     int i, j;
  281.  
  282.     glRotatef(alpha, 1, 0, 0);
  283.     glRotatef(beta, 0, 1, 0);
  284.     glRotatef(gamma, 0, 0, 1);
  285.  
  286.     glMatrixMode(GL_MODELVIEW);
  287.     glLoadIdentity();
  288.  
  289.     for (i = 0; i < stop_i-1; i += 1) {
  290.         for (j = 0; j < stop_j-1; j += 1) {
  291.             //top
  292.             glBegin(GL_POLYGON);
  293.             glColor3f(0.5, 0.5, 0.5);
  294.             glVertex3f(top[i][j].x, top[i][j].y, top[i][j].z);
  295.             glColor3f(0, 0, 0);
  296.             glVertex3f(top[i][j + 1].x, top[i][j + 1].y, top[i][j + 1].z);
  297.             glVertex3f(top[i + 1][j + 1].x, top[i + 1][j + 1].y, top[i + 1][j + 1].z);
  298.             glVertex3f(top[i + 1][j].x, top[i + 1][j].y, top[i + 1][j].z);
  299.             glEnd();
  300.  
  301.  
  302.             //bot
  303.             glBegin(GL_POLYGON);
  304.            
  305.             glColor3f(0.3, 0.3, 0.3);
  306.             glTexCoord2f(0.0f, 0.0f);
  307.             glVertex3f(bot[i][j].x, bot[i][j].y, bot[i][j].z);
  308.            
  309.             glColor3f(0, 0, 0);
  310.             glTexCoord2f(0.0f, 1.0f);
  311.             glVertex3f(bot[i][j + 1].x, bot[i][j + 1].y, bot[i][j + 1].z);
  312.            
  313.             glTexCoord2f(1.0f, 1.0f);
  314.             glVertex3f(bot[i + 1][j + 1].x, bot[i + 1][j + 1].y, bot[i + 1][j + 1].z);
  315.            
  316.             glTexCoord2f(1.0f, 0.0f);
  317.             glVertex3f(bot[i + 1][j].x, bot[i + 1][j].y, bot[i + 1][j].z);
  318.            
  319.             glEnd();
  320.  
  321.  
  322.             //sidelines
  323.             glBegin(GL_POLYGON);
  324.             glColor3f(0, 0, 0);
  325.             glVertex3f(side[i][j].x, side[i][j].y, side[i][j].z);
  326.             glColor3f(0.8, 0, 0);
  327.             glVertex3f(side[i][j + 1].x, side[i][j + 1].y, side[i][j + 1].z);
  328.             glColor3f(0, 0.8, 0);
  329.             glVertex3f(side[i + 1][j + 1].x, side[i + 1][j + 1].y, side[i + 1][j + 1].z);
  330.             glColor3f(0, 0, 0.8);
  331.             glVertex3f(side[i + 1][j].x, side[i + 1][j].y, side[i + 1][j].z);
  332.             glEnd();
  333.         }
  334.     }
  335. }
  336.  
  337. void tweenking()
  338. {
  339.     int i, j, c;
  340.     GLfloat ai, bi;
  341.     //Bezier cube:
  342.     //(1-t)^3*p0 + 3t(1-t)^2*p1 + 3*t^2*(1-t)*p2 + t^3*p3
  343.     printf("twinkie\n");
  344.    
  345.     for (t = 0, c = 0; c < 20; t += dt, c++) {
  346.         for (i = 0; i < stop_i; i += 1) {
  347.             for (j = 0; j < stop_j; j += 1) {
  348.                 ai = cone_bot[i][j].y;
  349.                 bi = cone_bot[i][j].y * 2;
  350.  
  351.                 cone_top[i][j].x = cone_top[i][j].x;
  352.                 cone_top[i][j].y = cone_top[i][j].y;
  353.                 cone_top[i][j].z = cone_top[i][j].z ;
  354.  
  355.                 cone_bot[i][j].x = cone_bot[i][j].x;
  356.                 cone_bot[i][j].y = (1 - t*t)*ai + t*t*bi;
  357.                 cone_bot[i][j].z = cone_bot[i][j].z;
  358.  
  359.                 cone_side[i][j].x = cone_side[i][j].x;
  360.                 cone_side[i][j].y = cone_side[i][j].y;
  361.                 cone_side[i][j].z = cone_side[i][j].z;
  362.             }
  363.         }
  364.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  365.         draw_figure(cone_top, cone_side, cone_bot);
  366.         Sleep(10);
  367.     }
  368.     printf("twinkie stop\n");
  369. }
  370.  
  371. void set_tex()
  372. {
  373.     landTexture = LoadBitmapFile("photo.bmp", &landInfo);
  374.     //if (!landTexture)
  375.     //  return false;
  376.     glTexEnvf(GL_FRONT_AND_BACK, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  377.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  378.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  379.     gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, landInfo.biHeight, landInfo.biWidth, GL_RGB, GL_UNSIGNED_BYTE, landTexture);
  380. }
  381.  
  382. void controls(GLFWwindow* window, int key, int scancode, int action, int mods)
  383. {
  384.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  385.         glfwSetWindowShouldClose(window, GL_TRUE);
  386.  
  387.     switch (key) {
  388.     case (GLFW_KEY_SPACE) :
  389.         if (action == GLFW_PRESS) {
  390.         alpha = 0;
  391.         beta = 0;
  392.         gamma = 0;
  393.         h = 2;
  394.         r = 1;
  395.         freq_x = 3;
  396.         freq_y = 3;
  397.         count_cone();
  398.         count_cylinder();
  399.         }
  400.                           break;
  401.     case (GLFW_KEY_UP) :
  402.         if (action == GLFW_PRESS) {
  403.         if (h <= MAXHEIGHT) {
  404.             h += 2;
  405.             freq_y++;
  406.             count_cone();
  407.             count_cylinder();
  408.         }
  409.         }
  410.                        break;
  411.     case (GLFW_KEY_DOWN) :
  412.         if (action == GLFW_PRESS) {
  413.         if (h > MINHEIGHT) {
  414.             h -= 2;
  415.             freq_y--;
  416.             count_cone();
  417.             count_cylinder();
  418.         }
  419.         }
  420.                          break;
  421.     case (GLFW_KEY_RIGHT) :
  422.         if (action == GLFW_PRESS) {
  423.         if (r < MAXRAD) {
  424.             r++;
  425.             count_cone();
  426.             count_cylinder();
  427.         }
  428.         }
  429.                           break;
  430.     case (GLFW_KEY_LEFT) :
  431.         if (action == GLFW_PRESS) {
  432.         if (r > MINRAD) {
  433.             r--;
  434.             count_cone();
  435.             count_cylinder();
  436.         }
  437.         }
  438.                          break;
  439.     case (GLFW_KEY_R) :
  440.         if (action == GLFW_PRESS) {
  441.         if (freq_x <= MAXFREQ_X) {
  442.             freq_x++;
  443.             count_cone();
  444.             count_cylinder();
  445.         }
  446.         }
  447.                       break;
  448.     case (GLFW_KEY_F) :
  449.         if (action == GLFW_PRESS) {
  450.         if (freq_x > MINFREQ_X) {
  451.             freq_x--;
  452.             count_cone();
  453.             count_cylinder();
  454.         }
  455.         }
  456.                       break;
  457.     case (GLFW_KEY_V) :
  458.         if (action == GLFW_PRESS) {
  459.             if (type == 1) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  460.             if (type == -1) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  461.         }
  462.         break;
  463.  
  464.     case (GLFW_KEY_T) :
  465.         if (action == GLFW_PRESS) {
  466.             twinkie_flag = !twinkie_flag;
  467.             tweenking();
  468.         }
  469.         break;
  470.     case (GLFW_KEY_Y) :
  471.         if (action == GLFW_PRESS) {
  472.         tex_flag = !tex_flag;
  473.         if (tex_flag) {
  474.             glEnable(GL_TEXTURE_2D);
  475.         }
  476.         else {
  477.             glDisable(GL_TEXTURE_2D);
  478.         }
  479.         }
  480.                       break;
  481.     }
  482.  
  483. }
  484.  
  485. GLfloat cabinet_view_matrix[] = {
  486.     1, 0, 0, 0,
  487.     0, 1, 0, 0,
  488.     -0.5*cos(M_PI / 6), -0.5*sin(M_PI / 6), -1, 0,
  489.     0, 0, 0, 1
  490. };
  491.  
  492. /*
  493. void animation_compression(double k){
  494.     int i, j;
  495.     double t;
  496.     int counter;
  497.     GLdouble ayc, byc, ayf, byf;
  498.     long x;
  499.  
  500.     for (t = 0, counter = 20; counter >= 0; t += STEP, counter--){
  501.         for (i = 0; i <= ACCURACY; i++){
  502.             for (j = 0; j < ACCURACY; j++){
  503.                 ayc = my_cone[i][j].y;  ayf = my_foundament[i][j].y;
  504.                 byc = my_cone[i][j].y * k; byf = my_foundament[i][j].y * k;
  505.                 my_cone[i][j].y = (1 - t*t)*ayc + t*t*byc;
  506.                 my_foundament[i][j].y = (1 - t*t)*ayf + t*t*byf;
  507.             }
  508.         }
  509.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  510.         draw();
  511.         Sleep(20);
  512.     }
  513. }*/
  514.  
  515. void display(GLFWwindow* window)
  516. {
  517.     tex_flag = false;
  518.     twinkie_flag = false;
  519.  
  520.     t = 0;
  521.     freq_x = 3;
  522.     freq_y = 3;
  523.     type = -1;
  524.     h = 3;
  525.     r = 1;
  526.     alpha = 0;
  527.     beta = 0;
  528.     gamma = 0;
  529.  
  530.     count_cone();
  531.     count_cylinder();
  532.  
  533.     imageData = LoadBitmapFile("photo.bmp", &bitmapInfoHeader);
  534.  
  535.     set_tex();
  536.  
  537.     while (!glfwWindowShouldClose(window))
  538.     {
  539.         glClearColor(0.4, 0.4, 0.4, 1.0);
  540.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  541.  
  542.         if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) alpha -= ANGLE;
  543.         if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) alpha += ANGLE;
  544.         if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) beta -= ANGLE;
  545.         if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) beta += ANGLE;
  546.         if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) gamma -= ANGLE;
  547.         if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) gamma += ANGLE;
  548.  
  549.         glMatrixMode(GL_PROJECTION);
  550.         glLoadIdentity();
  551.         glLoadMatrixf(cabinet_view_matrix);
  552.         glOrtho(-10, 10, -10, 10, 10, -10);
  553.  
  554.  
  555.         if (twinkie_flag) tweenking();
  556.         else draw_figure(cone_top, cone_side, cone_bot);
  557.  
  558.  
  559.         glfwSwapBuffers(window);
  560.         //glfwWaitEvents();
  561.         glfwPollEvents();
  562.     }
  563.  
  564. }
  565.  
  566. int main(int argc, char** argv)
  567. {
  568.     // initialise GLFW
  569.     if (!glfwInit())
  570.     {
  571.         printf("glfwInit failed\n");
  572.         return -1;
  573.     }
  574.     glfwWindowHint(GLFW_SAMPLES, PC_MODE);
  575.     glfwSetErrorCallback(error_callback);
  576.  
  577.     //glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
  578.     //glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  579.     //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
  580.     GLFWwindow* window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test app", NULL, NULL);
  581.  
  582.     if (window == NULL)
  583.     {
  584.         printf("glfwOpenWindow failed.\n");
  585.         glfwTerminate();
  586.         return -2;
  587.     }
  588.  
  589.     int attrib;
  590.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
  591.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
  592.     attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
  593.  
  594.     glfwMakeContextCurrent(window);
  595.     glfwSetKeyCallback(window, controls);
  596.  
  597.     //glDepthFunc(GL_LEQUAL);
  598.     glEnable(GL_DEPTH_TEST);
  599.  
  600.     GLfloat ambientLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  601.     GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 0.7f };
  602.  
  603.     glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
  604.     glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
  605.  
  606.     glEnable(GL_LIGHT0);
  607.  
  608.     GLfloat lightPos[] = { -50.0f, 50.0f, 100.0f, 1.0f };
  609.     glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  610.     //glLightModelf(GL_LIGHT_MODEL_AMBIENT, ambientLight);
  611.    
  612.     if (NULL != window)
  613.     {
  614.         display(window);
  615.     }
  616.     glfwDestroyWindow(window);
  617.     glfwTerminate();
  618.     return 0;
  619. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement