Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

texturesurf.c 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /*
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /* texturesurf.c
  39. * This program uses evaluators to generate a curved
  40. * surface and automatically generated texture coordinates.
  41. */
  42. #include <stdlib.h>
  43. #include <GL/glut.h>
  44. #include <math.h>
  45. GLfloat ctrlpoints[4][4][3] = {
  46. {{ -1.5, -1.5, 4.0}, { -0.5, -1.5, 2.0},
  47. {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}},
  48. {{ -1.5, -0.5, 1.0}, { -0.5, -0.5, 3.0},
  49. {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}},
  50. {{ -1.5, 0.5, 4.0}, { -0.5, 0.5, 0.0},
  51. {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}},
  52. {{ -1.5, 1.5, -2.0}, { -0.5, 1.5, -2.0},
  53. {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
  54. };
  55. GLfloat texpts[2][2][2] = {{{0.0, 0.0}, {0.0, 1.0}},
  56. {{1.0, 0.0}, {1.0, 1.0}}};
  57. void display(void)
  58. {
  59. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  60. glColor3f(1.0, 1.0, 1.0);
  61. glEvalMesh2(GL_FILL, 0, 20, 0, 20);
  62. glFlush();
  63. }
  64. #define imageWidth 64
  65. #define imageHeight 64
  66. GLubyte image[3*imageWidth*imageHeight];
  67. void makeImage(void)
  68. {
  69. int i, j;
  70. float ti, tj;
  71. for (i = 0; i < imageWidth; i++) {
  72. ti = 2.0*3.14159265*i/imageWidth;
  73. for (j = 0; j < imageHeight; j++) {
  74. tj = 2.0*3.14159265*j/imageHeight;
  75. image[3*(imageHeight*i+j)] = (GLubyte) 127*(1.0+sin(ti));
  76. image[3*(imageHeight*i+j)+1] = (GLubyte) 127*(1.0+cos(2*tj));
  77. image[3*(imageHeight*i+j)+2] = (GLubyte) 127*(1.0+cos(ti+tj));
  78. }
  79. }
  80. }
  81. void myinit(void)
  82. {
  83. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
  84. 0, 1, 12, 4, &ctrlpoints[0][0][0]);
  85. glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2,
  86. 0, 1, 4, 2, &texpts[0][0][0]);
  87. glEnable(GL_MAP2_TEXTURE_COORD_2);
  88. glEnable(GL_MAP2_VERTEX_3);
  89. glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
  90. makeImage();
  91. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  92. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  93. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  94. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  95. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  96. glTexImage2D(GL_TEXTURE_2D, 0, 3, imageWidth, imageHeight, 0,
  97. GL_RGB, GL_UNSIGNED_BYTE, image);
  98. glEnable(GL_TEXTURE_2D);
  99. glEnable(GL_DEPTH_TEST);
  100. glEnable(GL_NORMALIZE);
  101. glShadeModel (GL_FLAT);
  102. }
  103. void myReshape(int w, int h)
  104. {
  105. glViewport(0, 0, w, h);
  106. glMatrixMode(GL_PROJECTION);
  107. glLoadIdentity();
  108. if (w <= h)
  109. glOrtho(-4.0, 4.0, -4.0*(GLfloat)h/(GLfloat)w,
  110. 4.0*(GLfloat)h/(GLfloat)w, -4.0, 4.0);
  111. else
  112. glOrtho(-4.0*(GLfloat)w/(GLfloat)h,
  113. 4.0*(GLfloat)w/(GLfloat)h, -4.0, 4.0, -4.0, 4.0);
  114. glMatrixMode(GL_MODELVIEW);
  115. glLoadIdentity();
  116. glRotatef(85.0, 1.0, 1.0, 1.0);
  117. }
  118. static void
  119. key(unsigned char k, int x, int y)
  120. {
  121. switch (k) {
  122. case 27: /* Escape */
  123. exit(0);
  124. break;
  125. default:
  126. return;
  127. }
  128. glutPostRedisplay();
  129. }
  130. int main(int argc, char** argv)
  131. {
  132. glutInit(&argc, argv);
  133. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  134. glutCreateWindow (argv[0]);
  135. myinit();
  136. glutReshapeFunc (myReshape);
  137. glutDisplayFunc(display);
  138. glutKeyboardFunc(key);
  139. glutMainLoop();
  140. return 0; /* ANSI C requires main to return int. */
  141. }