Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include "pch.h"
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <string>
  5. #include "glut.h"
  6.  
  7. GLfloat TexP1[] = { 0,1,0,0 };
  8. GLfloat TexP2[] = { 0,0,1,0 };
  9. GLubyte TexI[] =
  10. { 255,0,0,
  11. 255,0,0,
  12. 255,255,0,
  13. 255,255,0,
  14. 0,255,0,
  15. 0,255,0,
  16. 0,0,255,
  17. 0,0,255
  18. };
  19. GLfloat texpts[2][2][2] = { 0,0,0,2,2,0,2,2 };
  20. GLUnurbsObj* theNurb;
  21. GLUquadricObj* theqw;
  22.  
  23. // массив точек определяющего многоугольника
  24. GLfloat pts1[10][4] = {
  25. {1, 0.866, -0.3, 1},
  26. {1, 0.866, 0.3, 1},
  27. { 0.5, 0.0, -0.3, 1 },
  28. { 0.5,0.0,0.3,1 },
  29. { 0.0,0.866,-0.3,1 },
  30. { 0.0, 0.866, 0.3, 1 },
  31. { -0.5,0.0,-0.3,1 },
  32. { -0.5,0.0,0.3,1 },
  33. {-1, 0.866, -0.3, 1},
  34. {-1, 0.866, 0.3, 1},
  35. };
  36.  
  37. void init(void)
  38. {
  39. glClearColor(0.5, 0.75, 0.75, 1);
  40. theNurb = gluNewNurbsRenderer();
  41. theqw = gluNewQuadric();
  42. glEnable(GL_DEPTH_TEST);
  43. gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25);
  44. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  45. glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  46. glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  47. glTexImage1D(GL_TEXTURE_1D, 0, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, TexI);
  48. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  49. //gluQuadricTexture(theqw, true);
  50. glEnable(GL_TEXTURE_1D);
  51. }
  52. void Display()
  53. {
  54. GLfloat knot[8] = { 0.0,0.0,0.0,1.0, 2.0,3.0, 3.0, 3.0};
  55. GLfloat knot1[4] = { 0,0,1,1 };
  56. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  57. glRotatef(0.01, 1, 1, 1);
  58. glColor3f(1, 0, 0);
  59. glEnable(GL_TEXTURE_GEN_S);
  60. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  61. glTexGenfv(GL_S, GL_OBJECT_PLANE, TexP1);
  62. GLfloat temp[10][4];
  63. for (int j = 0; j < 10; ++j) {
  64. for (int z = 0; z < 4; ++z) {
  65. temp[j][z] = pts1[j][z];
  66. if (j == 2 || j == 3) {
  67. temp[j][z] = pts1[j][z] * 1;
  68. }
  69. }
  70. };
  71. gluBeginSurface(theNurb);
  72. gluNurbsSurface(theNurb, 8, knot, 4, knot1, 2 * 4, 4, &temp[0][0], 3, 2, GL_MAP2_VERTEX_4);
  73. //glFlush();
  74. glutPostRedisplay();
  75. glutSwapBuffers();
  76. }
  77. void main()
  78. {
  79. glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  80. glutInitWindowSize(480, 480);
  81. glutInitWindowPosition(100, 100);
  82. glutCreateWindow(" ");
  83. init();
  84. glutDisplayFunc(Display);
  85. glutMainLoop();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement