Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // glfw_30.cpp : Defines the entry point for the console application.
- // http://www.glfw.org/docs/latest/quick.html
- #include "stdafx.h"
- #include <time.h>
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <vector>
- #define SCREEN_WIDTH 1000
- #define SCREEN_HEIGHT 1000
- #define PC_MODE 16
- #define CONSOLE_MODE 0
- #define MAXRAD 4
- #define MINRAD 1
- #define MAXHEIGHT 7
- #define MINHEIGHT 1
- #define MAXFREQ_X 40
- #define MINFREQ_X 3
- #define ANGLE 2
- #define TWINKIE_STEPS 1000
- typedef struct {
- float x, y, z;
- } coord;
- typedef struct cone{
- int type;
- int top_rad, bot_rad, height;
- int freq_x, freq_y;
- int angle_x, angle_y, angle_z;
- std::vector<std::vector<coord>> cone_top;
- std::vector<std::vector<coord>> cone_bot;
- std::vector<std::vector<coord>> cone_side;
- }prepare_ur_conus;
- std::vector<std::vector<coord>> cone_top;
- std::vector<std::vector<coord>> cone_bot;
- std::vector<std::vector<coord>> cone_side;
- std::vector<std::vector<coord>> cyl_top;
- std::vector<std::vector<coord>> cyl_bot;
- std::vector<std::vector<coord>> cyl_side;
- std::vector<std::vector<coord>> final_top;
- std::vector<std::vector<coord>> final_bot;
- std::vector<std::vector<coord>> final_side;
- int k = 1;
- bool twinkie_flag;
- int type, stop_i, stop_j, freq_x, freq_y;
- float t = 0, dt = 1 / TWINKIE_STEPS;
- static float alpha, beta, gamma, a, b, c, h, r;
- static void error_callback(int error, const char* description)
- {
- fputs(description, stderr);
- }
- void free_vect(std::vector<std::vector<coord>>& vect)
- {
- for (int i = 0; i < freq_y + 1; i++) {
- vect[i].clear();
- vect[i].shrink_to_fit();
- }
- vect.clear();
- vect.shrink_to_fit();
- }
- void copy_regular_vertices_to_final_vector()
- {
- }
- void count_cylinder()
- {
- int i = 0, j = 0, rad = r;
- float angle = 0, dangle, height, dheight, drad;
- height = h;
- dangle = 2 * M_PI / freq_x;
- dheight = height / freq_y;
- drad = rad / (float)freq_y;
- //count size of array
- j = 0;
- while (angle <= 2 * M_PI + dangle) {
- angle += dangle;
- j++;
- }
- stop_j = j;
- cyl_top.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cyl_top[i].resize(stop_j + 1);
- cyl_bot.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cyl_bot[i].resize(stop_j + 1);
- cyl_side.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cyl_side[i].resize(stop_j + 1);
- for (i = 0; i < freq_y; i += 1) {
- for (j = 0, angle = 0; angle <= 2 * M_PI + dangle; j += 1, angle += dangle) {
- cyl_top[i][j].x = (0 + drad*i)*cos(angle);
- cyl_top[i][j].y = height;
- cyl_top[i][j].z = (0 + drad*i)*sin(angle);
- cyl_top[i][j + 1].x = (0 + drad*i)*cos(angle + dangle);
- cyl_top[i][j + 1].y = height;
- cyl_top[i][j + 1].z = (0 + drad*i)*sin(angle + dangle);
- cyl_top[i + 1][j + 1].x = (0 + drad*(i + 1))*cos(angle + dangle);
- cyl_top[i + 1][j + 1].y = height;
- cyl_top[i + 1][j + 1].z = (0 + drad*(i + 1))*sin(angle + dangle);
- cyl_top[i + 1][j].x = (0 + drad*(i + 1))*cos(angle);
- cyl_top[i + 1][j].y = height;
- cyl_top[i + 1][j].z = (0 + drad*(i + 1))*sin(angle);
- cyl_bot[i][j].x = (0 + drad*i)*cos(angle);
- cyl_bot[i][j].y = 0;
- cyl_bot[i][j].z = (0 + drad*i)*sin(angle);
- cyl_bot[i][j + 1].x = (0 + drad*i)*cos(angle + dangle);
- cyl_bot[i][j + 1].y = 0;
- cyl_bot[i][j + 1].z = (0 + drad*i)*sin(angle + dangle);
- cyl_bot[i + 1][j + 1].x = (0 + drad*(i + 1))*cos(angle + dangle);
- cyl_bot[i + 1][j + 1].y = 0;
- cyl_bot[i + 1][j + 1].z = (0 + drad*(i + 1))*sin(angle + dangle);
- cyl_bot[i + 1][j].x = (0 + drad*(i + 1))*cos(angle);
- cyl_bot[i + 1][j].y = 0;
- cyl_bot[i + 1][j].z = (0 + drad*(i + 1))*sin(angle);
- cyl_side[i][j].x = rad*cos(angle);
- cyl_side[i][j].y = height - dheight*i;
- cyl_side[i][j].z = rad*sin(angle);
- cyl_side[i][j + 1].x = rad*cos(angle + dangle);
- cyl_side[i][j + 1].y = height - dheight*i;
- cyl_side[i][j + 1].z = rad*sin(angle + dangle);
- cyl_side[i + 1][j + 1].x = rad*cos(angle + dangle);
- cyl_side[i + 1][j + 1].y = height - dheight*(i + 1);
- cyl_side[i + 1][j + 1].z = rad*sin(angle + dangle);
- cyl_side[i + 1][j].x = rad*cos(angle);
- cyl_side[i + 1][j].y = height - dheight*(i + 1);
- cyl_side[i + 1][j].z = rad*sin(angle);
- }
- }
- }
- void count_cone()
- {
- int i = 0, j = 0, top_rad = r, bot_rad = r * 2;
- float angle = 0, dangle, height, dheight, drad, drad2;
- height = h;
- dangle = 2 * M_PI / freq_x;
- dheight = height / freq_y;
- drad = (bot_rad - top_rad) / (float)freq_y;
- drad2 = bot_rad / (float)freq_y;
- //count size of array
- j = 0;
- while (angle <= 2 * M_PI + dangle) {
- angle += dangle;
- j++;
- }
- stop_j = j;
- //allocate memory for top_ side_ vertices
- cone_top.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cone_top[i].resize(stop_j + 1);
- cone_bot.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cone_bot[i].resize(stop_j + 1);
- cone_side.resize(freq_y + 1);
- for (i = 0; i < freq_y + 1; i++) cone_side[i].resize(stop_j + 1);
- //count vert
- for (i = 0; i < freq_y; i += 1) {
- for (j = 0, angle = 0; angle <= 2 * M_PI + dangle; j += 1, angle += dangle) {
- cone_top[i][j].x = (0 + drad*i)*cos(angle);
- cone_top[i][j].y = height;
- cone_top[i][j].z = (0 + drad*i)*sin(angle);
- cone_top[i][j + 1].x = (0 + drad*i)*cos(angle + dangle);
- cone_top[i][j + 1].y = height;
- cone_top[i][j + 1].z = (0 + drad*i)*sin(angle + dangle);
- cone_top[i + 1][j + 1].x = (0 + drad*(i + 1))*cos(angle + dangle);
- cone_top[i + 1][j + 1].y = height;
- cone_top[i + 1][j + 1].z = (0 + drad*(i + 1))*sin(angle + dangle);
- cone_top[i + 1][j].x = (0 + drad*(i + 1))*cos(angle);
- cone_top[i + 1][j].y = height;
- cone_top[i + 1][j].z = (0 + drad*(i + 1))*sin(angle);
- cone_bot[i][j].x = (0 + drad2*i)*cos(angle);
- cone_bot[i][j].y = 0;
- cone_bot[i][j].z = (0 + drad2*i)*sin(angle);
- cone_bot[i][j + 1].x = (0 + drad2*i)*cos(angle + dangle);
- cone_bot[i][j + 1].y = 0;
- cone_bot[i][j + 1].z = (0 + drad2*i)*sin(angle + dangle);
- cone_bot[i + 1][j + 1].x = (0 + drad2*(i + 1))*cos(angle + dangle);
- cone_bot[i + 1][j + 1].y = 0;
- cone_bot[i + 1][j + 1].z = (0 + drad2*(i + 1))*sin(angle + dangle);
- cone_bot[i + 1][j].x = (0 + drad2*(i + 1))*cos(angle);
- cone_bot[i + 1][j].y = 0;
- cone_bot[i + 1][j].z = (0 + drad2*(i + 1))*sin(angle);
- cone_side[i][j].x = (top_rad + drad*i)*cos(angle);
- cone_side[i][j].y = height - dheight*i;
- cone_side[i][j].z = (top_rad + drad*i)*sin(angle);
- cone_side[i][j + 1].x = (top_rad + drad*i)*cos(angle + dangle);
- cone_side[i][j + 1].y = height - dheight*i;
- cone_side[i][j + 1].z = (top_rad + drad*i)*sin(angle + dangle);
- cone_side[i + 1][j + 1].x = (top_rad + drad*(i + 1))*cos(angle + dangle);
- cone_side[i + 1][j + 1].y = height - dheight*(i + 1);
- cone_side[i + 1][j + 1].z = (top_rad + drad*(i + 1))*sin(angle + dangle);
- cone_side[i + 1][j].x = (top_rad + drad*(i + 1))*cos(angle);
- cone_side[i + 1][j].y = height - dheight*(i + 1);
- cone_side[i + 1][j].z = (top_rad + drad*(i + 1))*sin(angle);
- }
- }
- stop_i = i;
- stop_j = j;
- printf("coordinates renewed: h=%.2f, top_r=%d, fr_x=%d, fr_y=%d\n", height, top_rad, freq_x, freq_y);
- }
- void draw_figure(
- std::vector<std::vector<coord>>& top,
- std::vector<std::vector<coord>>& bot,
- std::vector<std::vector<coord>>& side
- )
- {
- int i, j;
- glRotatef(alpha, 1, 0, 0);
- glRotatef(beta, 0, 1, 0);
- glRotatef(gamma, 0, 0, 1);
- for (i = 0; i < stop_i; i += 1) {
- for (j = 0; j < stop_j; j += 1) {
- //top
- glBegin(GL_POLYGON);
- glColor3f(0.5, 0.5, 0.5);
- glVertex3f(top[i][j].x, top[i][j].y, top[i][j].z);
- glColor3f(0, 0, 0);
- glVertex3f(top[i][j + 1].x, top[i][j + 1].y, top[i][j + 1].z);
- glVertex3f(top[i + 1][j + 1].x, top[i + 1][j + 1].y, top[i + 1][j + 1].z);
- glVertex3f(top[i + 1][j].x, top[i + 1][j].y, top[i + 1][j].z);
- glEnd();
- //bot
- glBegin(GL_POLYGON);
- glColor3f(0.3, 0.3, 0.3);
- glVertex3f(bot[i][j].x, bot[i][j].y, bot[i][j].z);
- glColor3f(0, 0, 0);
- glVertex3f(bot[i][j + 1].x, bot[i][j + 1].y, bot[i][j + 1].z);
- glVertex3f(bot[i + 1][j + 1].x, bot[i + 1][j + 1].y, bot[i + 1][j + 1].z);
- glVertex3f(bot[i + 1][j].x, bot[i + 1][j].y, bot[i + 1][j].z);
- glEnd();
- //sidelines
- glBegin(GL_POLYGON);
- glColor3f(0, 0, 0);
- glVertex3f(side[i][j].x, side[i][j].y, side[i][j].z);
- glColor3f(0.8, 0, 0);
- glVertex3f(side[i][j + 1].x, side[i][j + 1].y, side[i][j + 1].z);
- glColor3f(0, 0.8, 0);
- glVertex3f(side[i + 1][j + 1].x, side[i + 1][j + 1].y, side[i + 1][j + 1].z);
- glColor3f(0, 0, 0.8);
- glVertex3f(side[i + 1][j].x, side[i + 1][j].y, side[i + 1][j].z);
- glEnd();
- }
- }
- }
- void func_1()
- {
- int i, j;
- if (t > 1) t = 1;
- std::vector<std::vector<coord>> gap_top;
- std::vector<std::vector<coord>> gap_bot;
- std::vector<std::vector<coord>> gap_side;
- gap_top.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_top[i].resize(stop_j);
- gap_bot.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_bot[i].resize(stop_j);
- gap_side.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_side[i].resize(stop_j);
- for (i = 0; i < stop_i; i += 1) {
- for (j = 0; j < stop_j; j += 1) {
- gap_top[i][j].x = 3 * 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_top[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_top[i][j].z = cone_top[i][j].z / 2;
- gap_bot[i][j].x = 3 * 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_bot[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_bot[i][j].z = cone_top[i][j].z / 2;
- gap_side[i][j].x = 3 * 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_side[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_side[i][j].z = cone_top[i][j].z / 2;
- }
- }
- //Bezier cube:
- //(1-t)^3*p0 + 3t(1-t)^2*p1 + 3*t^2*(1-t)*p2 + t^3*p3
- for (i = 0; i < stop_i; i += 1) {
- for (j = 0; j < stop_j; j += 1) {
- final_top[i][j].x = cone_top[i][j].x*(t - 1)*(t - 1) + gap_top[i][j].x*t*(t - 1) + cyl_top[i][j].x*t*t;
- final_top[i][j].y = cone_top[i][j].y*(t - 1)*(t - 1) + gap_top[i][j].y*t*(t - 1) + cyl_top[i][j].y*t*t;
- final_top[i][j].z = cone_top[i][j].z*(t - 1)*(t - 1) + gap_top[i][j].z*t*(t - 1) + cyl_top[i][j].z*t*t;
- final_bot[i][j].x = cone_bot[i][j].x*(t - 1)*(t - 1) + gap_bot[i][j].x*t*(t - 1) + cyl_bot[i][j].x*t*t;
- final_bot[i][j].y = cone_bot[i][j].y*(t - 1)*(t - 1) + gap_bot[i][j].y*t*(t - 1) + cyl_bot[i][j].y*t*t;
- final_bot[i][j].z = cone_bot[i][j].z*(t - 1)*(t - 1) + gap_bot[i][j].z*t*(t - 1) + cyl_bot[i][j].z*t*t;
- final_side[i][j].x = cone_side[i][j].x*(t - 1)*(t - 1) + gap_side[i][j].x*t*(t - 1) + cyl_side[i][j].x*t*t;
- final_side[i][j].y = cone_side[i][j].y*(t - 1)*(t - 1) + gap_side[i][j].y*t*(t - 1) + cyl_side[i][j].y*t*t;
- final_side[i][j].z = cone_side[i][j].z*(t - 1)*(t - 1) + gap_side[i][j].z*t*(t - 1) + cyl_side[i][j].z*t*t;
- }
- }
- if (t == 1) {
- k = 0;
- twinkie_flag = false;
- }
- t += dt;
- free_vect(gap_top);
- free_vect(gap_bot);
- free_vect(gap_side);
- }
- void func_2()
- {
- int i, j;
- if (t < 0) t = 0;
- std::vector<std::vector<coord>> gap_top;
- std::vector<std::vector<coord>> gap_bot;
- std::vector<std::vector<coord>> gap_side;
- gap_top.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_top[i].resize(stop_j);
- gap_bot.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_bot[i].resize(stop_j);
- gap_side.resize(stop_i);
- for (i = 0; i < stop_j; i++) gap_side[i].resize(stop_j);
- for (i = 0; i < stop_i; i += 1) {
- for (j = 0; j < stop_j; j += 1) {
- gap_top[i][j].x = 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_top[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_top[i][j].z = cone_top[i][j].z;
- gap_bot[i][j].x = 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_bot[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_bot[i][j].z = cone_top[i][j].z;
- gap_side[i][j].x = 0.5*(cyl_top[i][j].x - cone_top[i][j].x) + cone_top[i][j].x;
- gap_side[i][j].y = 0.5*(cyl_top[i][j].y - cone_top[i][j].y) + cone_top[i][j].y;
- gap_side[i][j].z = cone_top[i][j].z;
- }
- }
- //Bezier cube:
- //(1-t)^3*p0 + 3t(1-t)^2*p1 + 3*t^2*(1-t)*p2 + t^3*p3
- for (i = 0; i < stop_i; i += 1) {
- for (j = 0; j < stop_j; j += 1) {
- final_top[i][j].x = cone_top[i][j].x*(t - 1)*(t - 1) + gap_top[i][j].x*t*(t - 1) + cyl_top[i][j].x*t*t;
- final_top[i][j].y = cone_top[i][j].y*(t - 1)*(t - 1) + gap_top[i][j].y*t*(t - 1) + cyl_top[i][j].y*t*t;
- final_top[i][j].z = cone_top[i][j].z*(t - 1)*(t - 1) + gap_top[i][j].z*t*(t - 1) + cyl_top[i][j].z*t*t;
- final_bot[i][j].x = cone_bot[i][j].x*(t - 1)*(t - 1) + gap_bot[i][j].x*t*(t - 1) + cyl_bot[i][j].x*t*t;
- final_bot[i][j].y = cone_bot[i][j].y*(t - 1)*(t - 1) + gap_bot[i][j].y*t*(t - 1) + cyl_bot[i][j].y*t*t;
- final_bot[i][j].z = cone_bot[i][j].z*(t - 1)*(t - 1) + gap_bot[i][j].z*t*(t - 1) + cyl_bot[i][j].z*t*t;
- final_side[i][j].x = cone_side[i][j].x*(t - 1)*(t - 1) + gap_side[i][j].x*t*(t - 1) + cyl_side[i][j].x*t*t;
- final_side[i][j].y = cone_side[i][j].y*(t - 1)*(t - 1) + gap_side[i][j].y*t*(t - 1) + cyl_side[i][j].y*t*t;
- final_side[i][j].z = cone_side[i][j].z*(t - 1)*(t - 1) + gap_side[i][j].z*t*(t - 1) + cyl_side[i][j].z*t*t;
- }
- }
- if (t == 0) {
- k = 1;
- twinkie_flag = false;
- }
- t -= dt;
- free_vect(gap_top);
- free_vect(gap_bot);
- free_vect(gap_side);
- }
- void controls(GLFWwindow* window, int key, int scancode, int action, int mods)
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- switch (key) {
- case (GLFW_KEY_SPACE) :
- if (action == GLFW_PRESS) {
- alpha = 0;
- beta = 0;
- gamma = 0;
- h = 2;
- r = 1;
- freq_x = 3;
- freq_y = 3;
- count_cone();
- count_cylinder();
- }
- break;
- case (GLFW_KEY_UP) :
- if (action == GLFW_PRESS) {
- if (h <= MAXHEIGHT) {
- h += 2;
- freq_y++;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_DOWN) :
- if (action == GLFW_PRESS) {
- if (h > MINHEIGHT) {
- h -= 2;
- freq_y--;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_RIGHT) :
- if (action == GLFW_PRESS) {
- if (r < MAXRAD) {
- r++;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_LEFT) :
- if (action == GLFW_PRESS) {
- if (r > MINRAD) {
- r--;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_R) :
- if (action == GLFW_PRESS) {
- if (freq_x <= MAXFREQ_X) {
- freq_x++;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_F) :
- if (action == GLFW_PRESS) {
- if (freq_x > MINFREQ_X) {
- freq_x--;
- count_cone();
- count_cylinder();
- }
- }
- break;
- case (GLFW_KEY_V) :
- if (action == GLFW_PRESS) {
- type = -type;
- if (type == 1) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- if (type == -1) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- }
- break;
- case (GLFW_KEY_T) :
- if (action == GLFW_PRESS) {
- twinkie_flag = !twinkie_flag;
- }
- break;
- }
- }
- GLfloat cabinet_view_matrix[] = {
- 1, 0, 0, 0,
- 0, 1, 0, 0,
- -0.5*cos(M_PI / 6), -0.5*sin(M_PI / 6), -1, 0,
- 0, 0, 0, 1
- };
- void display(GLFWwindow* window)
- {
- twinkie_flag = false;
- t = 0;
- freq_x = 3;
- freq_y = 3;
- type = -1;
- h = 3;
- r = 1;
- alpha = 0;
- beta = 0;
- gamma = 0;
- count_cone();
- count_cylinder();
- copy_regular_vertices_to_final_vector();
- while (!glfwWindowShouldClose(window))
- {
- glClearColor(0.4, 0.4, 0.4, 1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) alpha -= ANGLE;
- if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) alpha += ANGLE;
- if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) beta -= ANGLE;
- if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) beta += ANGLE;
- if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) gamma -= ANGLE;
- if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) gamma += ANGLE;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glLoadMatrixf(cabinet_view_matrix);
- glOrtho(-10, 10, -10, 10, 10, -10);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- //draw_net();
- //draw_axis(-100, 100, -3, 100, -1, 100);
- if (twinkie_flag) {
- if (k) func_1();
- else func_2();
- draw_figure(final_top, final_bot, final_side);
- }
- else {
- draw_figure(cone_top, cone_bot, cone_side);
- }
- //copy_regular_vertices_to_final_vector();
- //draw_figure(cyl_top, cyl_bot, cyl_side);
- glfwSwapBuffers(window);
- //glfwWaitEvents();
- glfwPollEvents();
- }
- free_vect(cone_top);
- free_vect(cone_bot);
- free_vect(cone_side);
- }
- int main(int argc, char** argv)
- {
- // initialise GLFW
- if (!glfwInit())
- {
- printf("glfwInit failed\n");
- return -1;
- }
- glfwWindowHint(GLFW_SAMPLES, PC_MODE);
- glfwSetErrorCallback(error_callback);
- //glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
- //glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
- GLFWwindow* window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test app", NULL, NULL);
- if (window == NULL)
- {
- printf("glfwOpenWindow failed.\n");
- glfwTerminate();
- return -2;
- }
- int attrib;
- attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
- attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
- attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
- glfwMakeContextCurrent(window);
- glfwSetKeyCallback(window, controls);
- //glDepthFunc(GL_LEQUAL);
- glEnable(GL_DEPTH_TEST);
- GLfloat ambientLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 0.7f };
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
- glEnable(GL_LIGHT0);
- GLfloat lightPos[] = { -50.0f, 50.0f, 100.0f, 1.0f };
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
- //glLightModelf(GL_LIGHT_MODEL_AMBIENT, ambientLight);
- if (NULL != window)
- {
- display(window);
- }
- glfwDestroyWindow(window);
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement