|
| 1 | +// |
| 2 | +// Created by Сергей Кривонос on 16.08.17. |
| 3 | +// |
| 4 | + |
| 5 | +#include <GL/gl.h> |
| 6 | +#include <GL/glu.h> |
| 7 | +#include <GLUT/GLUT.h> |
| 8 | +#include <vector> |
| 9 | + |
| 10 | +//int main() |
| 11 | +//{ |
| 12 | +// auto hwnd = glutCreateWindow("MathTool"); |
| 13 | +// //Frustum(-1, 1, -1, 1, 1, -1); |
| 14 | +// return 0; |
| 15 | +//} |
| 16 | + |
| 17 | +GLfloat mat_red_diffuse[] = { 0.7, 0.7, 0.7, 1.0 }; |
| 18 | +GLfloat mat_green_diffuse[] = { 0.0, 0.7, 0.1, .5 }; |
| 19 | +GLfloat mat_blue_diffuse[] = { 0.0, 0.1, 0.7, 1.0 }; |
| 20 | +GLfloat mat_yellow_diffuse[] = { 0.7, 0.8, 0.1, 1.0 }; |
| 21 | +GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; |
| 22 | +GLfloat mat_shininess[] = { 100.0 }; |
| 23 | +GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 }; |
| 24 | +const int N = 16; |
| 25 | +GLfloat pts1[4][4][3], pts2[4][4][3]; |
| 26 | +GLfloat pts3[4][4][3], pts4[4][4][3]; |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +static void |
| 31 | +display(void) |
| 32 | +{ |
| 33 | + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 34 | + glCallList(1); |
| 35 | + glFlush(); |
| 36 | +} |
| 37 | + |
| 38 | +int |
| 39 | +main(int argc, char **argv) |
| 40 | +{ |
| 41 | + |
| 42 | + |
| 43 | + glutInit(&argc, argv); |
| 44 | + glutCreateWindow("x*y"); |
| 45 | + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); |
| 46 | + glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); |
| 47 | + glEnable(GL_LIGHTING); |
| 48 | + glEnable(GL_LIGHT0); |
| 49 | + glEnable(GL_DEPTH_TEST); |
| 50 | + glEnable(GL_AUTO_NORMAL); |
| 51 | + glEnable(GL_NORMALIZE); |
| 52 | + GLUnurbsObj * nurb = gluNewNurbsRenderer(); |
| 53 | + gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 2.0); |
| 54 | + gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_POINT); |
| 55 | + |
| 56 | + /* Build control points for NURBS mole hills. */ |
| 57 | + int u, v; |
| 58 | + for(u=0; u<4; u++) { |
| 59 | + for(v=0; v<4; v++) { |
| 60 | + GLfloat x = u; |
| 61 | + GLfloat y = v; |
| 62 | + |
| 63 | + /* Red. */ |
| 64 | + pts1[u][v][0] = 2.0*((GLfloat)x); |
| 65 | + pts1[u][v][1] = 2.0*((GLfloat)y); |
| 66 | + pts1[u][v][2] = x*y; |
| 67 | + |
| 68 | + /* Green. */ |
| 69 | + pts2[u][v][0] = 2.0*((GLfloat)x - 3.); |
| 70 | + pts2[u][v][1] = 2.0*((GLfloat)y - 3.0); |
| 71 | + pts2[3-u][3-v][2] = (-x*y); |
| 72 | + |
| 73 | + |
| 74 | + /* Blue. */ |
| 75 | + pts3[u][v][0] = 2.0*((GLfloat)x - 3.0); |
| 76 | + pts3[u][v][1] = 2.0*((GLfloat)y); |
| 77 | + pts3[3-u][v][2] = -x*y; |
| 78 | + |
| 79 | + |
| 80 | + /* Yellow. */ |
| 81 | + pts4[u][v][0] = 2.0*((GLfloat)x); |
| 82 | + pts4[u][v][1] = 2.0*((GLfloat)y - 3.0); |
| 83 | + pts4[u][3-v][2] = x*(-y); |
| 84 | + } |
| 85 | + } |
| 86 | +// /* Stretch up red's far right corner. */ |
| 87 | +// pts1[3][3][2] = 6; |
| 88 | +// /* Pull down green's near left corner a little. */ |
| 89 | +// pts2[0][0][2] = -2; |
| 90 | +// /* Turn up meeting of four corners. */ |
| 91 | +// pts1[0][0][2] = 1; |
| 92 | +// pts2[3][3][2] = 1; |
| 93 | +// pts3[3][0][2] = 1; |
| 94 | +// pts4[0][3][2] = 1; |
| 95 | + |
| 96 | + glMatrixMode(GL_PROJECTION); |
| 97 | + |
| 98 | + gluPerspective(105.0, 1.0, 2.0, 24.0); |
| 99 | + glMatrixMode(GL_MODELVIEW); |
| 100 | + glTranslatef(0.0, 0.0, -15.0); |
| 101 | + glRotatef(330.0, 1.0, 0.0, 0.0); |
| 102 | + |
| 103 | + glNewList(1, GL_COMPILE); |
| 104 | + /* Render red hill. */ |
| 105 | + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse); |
| 106 | + gluBeginSurface(nurb); |
| 107 | + gluNurbsSurface(nurb, 8, knots, 8, knots, |
| 108 | + 4 * 3, 3, &pts1[0][0][0], |
| 109 | + 4, 4, GL_MAP2_VERTEX_3); |
| 110 | + gluEndSurface(nurb); |
| 111 | + |
| 112 | + /* Render green hill. */ |
| 113 | + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green_diffuse); |
| 114 | + gluBeginSurface(nurb); |
| 115 | + gluNurbsSurface(nurb, 8, knots, 8, knots, |
| 116 | + 4 * 3, 3, &pts2[0][0][0], |
| 117 | + 4, 4, GL_MAP2_VERTEX_3); |
| 118 | + gluEndSurface(nurb); |
| 119 | + |
| 120 | + /* Render blue hill. */ |
| 121 | + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue_diffuse); |
| 122 | + gluBeginSurface(nurb); |
| 123 | + gluNurbsSurface(nurb, 8, knots, 8, knots, |
| 124 | + 4 * 3, 3, &pts3[0][0][0], |
| 125 | + 4, 4, GL_MAP2_VERTEX_3); |
| 126 | + gluEndSurface(nurb); |
| 127 | + |
| 128 | + /* Render yellow hill. */ |
| 129 | + glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_yellow_diffuse); |
| 130 | + gluBeginSurface(nurb); |
| 131 | + gluNurbsSurface(nurb, 8, knots, 8, knots, |
| 132 | + 4 * 3, 3, &pts4[0][0][0], |
| 133 | + 4, 4, GL_MAP2_VERTEX_3); |
| 134 | + gluEndSurface(nurb); |
| 135 | + glEndList(); |
| 136 | + |
| 137 | + glutDisplayFunc(display); |
| 138 | + glutMainLoop(); |
| 139 | + return 0; /* ANSI C requires main to return int. */ |
| 140 | +} |
0 commit comments