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.

vpeval.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Vertex program evaluators test.
  3. * Based on book/bezmesh.c
  4. *
  5. * Brian Paul
  6. * 22 June 2002
  7. */
  8. #include <assert.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #define GL_GLEXT_PROTOTYPES
  13. #include <GL/glut.h>
  14. /*
  15. * Transform position by modelview/projection.
  16. * Square incoming color.
  17. */
  18. static const char prog[] =
  19. "!!VP1.0\n"
  20. "# Typical modelview/projection\n"
  21. "DP4 o[HPOS].x, c[0], v[OPOS] ; # object x MVP -> clip\n"
  22. "DP4 o[HPOS].y, c[1], v[OPOS] ;\n"
  23. "DP4 o[HPOS].z, c[2], v[OPOS] ;\n"
  24. "DP4 o[HPOS].w, c[3], v[OPOS] ;\n"
  25. "MOV R0, v[COL0];\n # square the color\n"
  26. "MUL R0, R0, R0;\n"
  27. "MOV o[COL0], R0;\n # store output color\n"
  28. "END";
  29. static int program = 1;
  30. GLfloat ctrlpoints[4][4][4] =
  31. {
  32. {
  33. {-1.5, -1.5, 4.0, 1.0},
  34. {-0.5, -1.5, 2.0, 1.0},
  35. {0.5, -1.5, -1.0, 1.0},
  36. {1.5, -1.5, 2.0, 1.0}},
  37. {
  38. {-1.5, -0.5, 1.0, 1.0},
  39. {-0.5, -0.5, 3.0, 1.0},
  40. {0.5, -0.5, 0.0, 1.0},
  41. {1.5, -0.5, -1.0, 1.0}},
  42. {
  43. {-1.5, 0.5, 4.0, 1.0},
  44. {-0.5, 0.5, 0.0, 1.0},
  45. {0.5, 0.5, 3.0, 1.0},
  46. {1.5, 0.5, 4.0, 1.0}},
  47. {
  48. {-1.5, 1.5, -2.0, 1.0},
  49. {-0.5, 1.5, -2.0, 1.0},
  50. {0.5, 1.5, 0.0, 1.0},
  51. {1.5, 1.5, -1.0, 1.0}}
  52. };
  53. /*
  54. * +-------------+
  55. * |green |yellow
  56. * | |
  57. * | |
  58. * |black |red
  59. * +-------------+
  60. */
  61. GLfloat colorPoints[4][4][4] =
  62. {
  63. {
  64. {0.0, 0.0, 0.0, 1.0},
  65. {0.3, 0.0, 0.0, 1.0},
  66. {0.6, 0.0, 0.0, 1.0},
  67. {1.0, 0.0, 0.0, 1.0}},
  68. {
  69. {0.0, 0.3, 0.0, 1.0},
  70. {0.3, 0.3, 0.0, 1.0},
  71. {0.6, 0.3, 0.0, 1.0},
  72. {1.0, 0.3, 0.0, 1.0}},
  73. {
  74. {0.0, 0.6, 0.0, 1.0},
  75. {0.3, 0.6, 0.0, 1.0},
  76. {0.6, 0.6, 0.0, 1.0},
  77. {1.0, 0.6, 0.0, 1.0}},
  78. {
  79. {0.0, 1.0, 0.0, 1.0},
  80. {0.3, 1.0, 0.0, 1.0},
  81. {0.6, 1.0, 0.0, 1.0},
  82. {1.0, 1.0, 0.0, 1.0}}
  83. };
  84. void
  85. initlights(void)
  86. {
  87. GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
  88. GLfloat position[] = {0.0, 0.0, 2.0, 1.0};
  89. GLfloat mat_diffuse[] = {0.6, 0.6, 0.6, 1.0};
  90. GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
  91. GLfloat mat_shininess[] = {50.0};
  92. #if 0 /* no lighting for now */
  93. glEnable(GL_LIGHTING);
  94. glEnable(GL_LIGHT0);
  95. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  96. glLightfv(GL_LIGHT0, GL_POSITION, position);
  97. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  98. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  99. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  100. #endif
  101. }
  102. void
  103. display(void)
  104. {
  105. glClearColor(.3, .3, .3, 0);
  106. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  107. glPushMatrix();
  108. #if 1
  109. glRotatef(85.0, 1.0, 1.0, 1.0);
  110. #endif
  111. glEvalMesh2(GL_FILL, 0, 8, 0, 8);
  112. glPopMatrix();
  113. glFlush();
  114. }
  115. void
  116. myinit(int argc, char *argv[])
  117. {
  118. glClearColor(0.0, 0.0, 0.0, 1.0);
  119. glEnable(GL_DEPTH_TEST);
  120. initlights(); /* for lighted version only */
  121. glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
  122. if (argc > 1)
  123. program = 0;
  124. printf("Using vertex program attribs? %s\n", program ? "yes" : "no");
  125. if (!program) {
  126. glMap2f(GL_MAP2_VERTEX_4,
  127. 0.0, 1.0, 4, 4,
  128. 0.0, 1.0, 16, 4, &ctrlpoints[0][0][0]);
  129. glMap2f(GL_MAP2_COLOR_4,
  130. 0.0, 1.0, 4, 4,
  131. 0.0, 1.0, 16, 4, &colorPoints[0][0][0]);
  132. glEnable(GL_MAP2_VERTEX_4);
  133. glEnable(GL_MAP2_COLOR_4);
  134. /*
  135. glEnable(GL_AUTO_NORMAL);
  136. glEnable(GL_NORMALIZE);
  137. */
  138. }
  139. else {
  140. glMap2f(GL_MAP2_VERTEX_ATTRIB0_4_NV,
  141. 0.0, 1.0, 4, 4,
  142. 0.0, 1.0, 16, 4, &ctrlpoints[0][0][0]);
  143. glMap2f(GL_MAP2_VERTEX_ATTRIB3_4_NV,
  144. 0.0, 1.0, 4, 4,
  145. 0.0, 1.0, 16, 4, &colorPoints[0][0][0]);
  146. glEnable(GL_MAP2_VERTEX_ATTRIB0_4_NV);
  147. glEnable(GL_MAP2_VERTEX_ATTRIB3_4_NV);
  148. /*
  149. glEnable(GL_AUTO_NORMAL);
  150. glEnable(GL_NORMALIZE);
  151. */
  152. /* vertex program init */
  153. glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 1,
  154. strlen(prog), (const GLubyte *) prog);
  155. assert(glIsProgramNV(1));
  156. glBindProgramNV(GL_VERTEX_PROGRAM_NV, 1);
  157. /* track matrices */
  158. glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);
  159. glEnable(GL_VERTEX_PROGRAM_NV);
  160. }
  161. }
  162. void
  163. myReshape(int w, int h)
  164. {
  165. glViewport(0, 0, w, h);
  166. glMatrixMode(GL_PROJECTION);
  167. glLoadIdentity();
  168. if (w <= h)
  169. glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w,
  170. 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0);
  171. else
  172. glOrtho(-4.0 * (GLfloat) w / (GLfloat) h,
  173. 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0);
  174. glMatrixMode(GL_MODELVIEW);
  175. glLoadIdentity();
  176. }
  177. static void
  178. key(unsigned char k, int x, int y)
  179. {
  180. switch (k) {
  181. case 27: /* Escape */
  182. exit(0);
  183. break;
  184. default:
  185. return;
  186. }
  187. glutPostRedisplay();
  188. }
  189. int
  190. main(int argc, char **argv)
  191. {
  192. glutInit(&argc, argv);
  193. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  194. glutInitWindowPosition(0, 0);
  195. glutCreateWindow(argv[0]);
  196. myinit(argc, argv);
  197. glutReshapeFunc(myReshape);
  198. glutDisplayFunc(display);
  199. glutKeyboardFunc(key);
  200. glutMainLoop();
  201. return 0; /* ANSI C requires main to return int. */
  202. }