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.

fptest1.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Test GL_NV_fragment_program */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <GL/glut.h>
  9. static void Display( void )
  10. {
  11. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  12. glPushMatrix();
  13. glColor4f(0, 0.5, 0, 1);
  14. glBegin(GL_POLYGON);
  15. glVertex2f(-1, -1);
  16. glVertex2f( 1, -1);
  17. glVertex2f( 0, 1);
  18. glEnd();
  19. glPopMatrix();
  20. glutSwapBuffers();
  21. }
  22. static void Reshape( int width, int height )
  23. {
  24. glViewport( 0, 0, width, height );
  25. glMatrixMode( GL_PROJECTION );
  26. glLoadIdentity();
  27. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  28. glMatrixMode( GL_MODELVIEW );
  29. glLoadIdentity();
  30. glTranslatef( 0.0, 0.0, -15.0 );
  31. }
  32. static void Key( unsigned char key, int x, int y )
  33. {
  34. (void) x;
  35. (void) y;
  36. switch (key) {
  37. case 27:
  38. exit(0);
  39. break;
  40. }
  41. glutPostRedisplay();
  42. }
  43. static void Init( void )
  44. {
  45. static const char *prog1 =
  46. "!!FP1.0\n"
  47. "MUL o[COLR], R0, f[WPOS]; \n"
  48. "ADD o[COLH], H3, f[TEX0]; \n"
  49. "ADD_SAT o[COLH], H3, f[TEX0]; \n"
  50. "ADDX o[COLH], H3, f[TEX0]; \n"
  51. "ADDHC o[COLH], H3, f[TEX0]; \n"
  52. "ADDXC o[COLH], H3, f[TEX0]; \n"
  53. "ADDXC_SAT o[COLH], H30, f[TEX0]; \n"
  54. "MUL o[COLR].xy, R0.wzyx, f[WPOS]; \n"
  55. "MUL o[COLR], H0, f[WPOS]; \n"
  56. "MUL o[COLR], -H0, f[WPOS]; \n"
  57. "MOV RC, H1; \n"
  58. "MOV HC, H2; \n"
  59. ;
  60. /* masked updates */
  61. static const char *prog2 =
  62. "!!FP1.0\n"
  63. "DEFINE foo = {1, 2, 3, 4}; \n"
  64. "DEFINE foo2 = 5; \n"
  65. "DECLARE foo = {5, 6, 7, 8}; \n"
  66. "DECLARE bar = 3; \n"
  67. "DECLARE bar2; \n"
  68. "DECLARE bar3 = bar; \n"
  69. "DECLARE bar4 = { a, b, c, d }; \n"
  70. "MOV o[COLR], R0; \n"
  71. "MOV o[COLR].xy, R0; \n"
  72. "MOV o[COLR] (NE), R0; \n"
  73. "MOV o[COLR] (NE.wzyx), R0; \n"
  74. "MOV o[COLR].xy (NE.wzyx), R0; \n"
  75. "KIL NE; \n"
  76. "KIL EQ.xyxy; \n"
  77. ;
  78. /* double the color */
  79. static const char *prog3 =
  80. "!!FP1.0\n"
  81. "MOV R0, f[COL0]; \n"
  82. "ADD o[COLR], R0, f[COL0]; \n"
  83. ;
  84. GLuint progs[20];
  85. glGenProgramsNV(20, progs);
  86. assert(progs[0]);
  87. assert(progs[1]);
  88. assert(progs[0] != progs[1]);
  89. glGenProgramsNV(3, progs + 2);
  90. assert(progs[2]);
  91. assert(progs[3]);
  92. assert(progs[2] != progs[3]);
  93. assert(progs[0] != progs[2]);
  94. glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[0],
  95. strlen(prog1),
  96. (const GLubyte *) prog1);
  97. assert(glIsProgramNV(progs[0]));
  98. glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[1],
  99. strlen(prog2),
  100. (const GLubyte *) prog2);
  101. assert(glIsProgramNV(progs[1]));
  102. glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[2],
  103. strlen(prog2),
  104. (const GLubyte *) prog3);
  105. assert(glIsProgramNV(progs[2]));
  106. glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, progs[2]);
  107. glEnable(GL_FRAGMENT_PROGRAM_NV);
  108. glEnable(GL_ALPHA_TEST);
  109. glAlphaFunc(GL_ALWAYS, 0.0);
  110. printf("glGetError = %d\n", (int) glGetError());
  111. }
  112. int main( int argc, char *argv[] )
  113. {
  114. glutInit( &argc, argv );
  115. glutInitWindowPosition( 0, 0 );
  116. glutInitWindowSize( 250, 250 );
  117. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  118. glutCreateWindow(argv[0]);
  119. glutReshapeFunc( Reshape );
  120. glutKeyboardFunc( Key );
  121. glutDisplayFunc( Display );
  122. Init();
  123. glutMainLoop();
  124. return 0;
  125. }