Advertisement
Guest User

Untitled

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