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.

tri-param.c 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <GL/glew.h>
  5. #include <GL/glut.h>
  6. static void Init( void )
  7. {
  8. static const char *modulate2D =
  9. "!!ARBfp1.0\n"
  10. "MOV result.color, program.local[32]; \n"
  11. "END"
  12. ;
  13. GLuint modulateProg;
  14. if (!GLEW_ARB_fragment_program) {
  15. printf("Error: GL_ARB_fragment_program not supported!\n");
  16. exit(1);
  17. }
  18. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  19. /* Setup the fragment program */
  20. glGenProgramsARB(1, &modulateProg);
  21. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
  22. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  23. strlen(modulate2D), (const GLubyte *)modulate2D);
  24. printf("glGetError = 0x%x\n", (int) glGetError());
  25. printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
  26. (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  27. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  28. glClearColor(.3, .3, .3, 0);
  29. }
  30. static void Reshape(int width, int height)
  31. {
  32. glViewport(0, 0, (GLint)width, (GLint)height);
  33. glMatrixMode(GL_PROJECTION);
  34. glLoadIdentity();
  35. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  36. glMatrixMode(GL_MODELVIEW);
  37. }
  38. static void Key(unsigned char key, int x, int y)
  39. {
  40. switch (key) {
  41. case 27:
  42. exit(1);
  43. default:
  44. break;
  45. }
  46. glutPostRedisplay();
  47. }
  48. static void Draw(void)
  49. {
  50. glClear(GL_COLOR_BUFFER_BIT);
  51. glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, .5, 0.25, 1);
  52. glBegin(GL_TRIANGLES);
  53. glColor3f(0,0,1);
  54. glVertex3f( 0.9, -0.9, -30.0);
  55. glColor3f(1,0,0);
  56. glVertex3f( 0.9, 0.0, -30.0);
  57. glColor3f(0,1,0);
  58. glVertex3f(-0.9, 0.0, -30.0);
  59. glEnd();
  60. glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 32, 0.25, 0, 0.25, 1);
  61. glBegin(GL_TRIANGLES);
  62. glColor3f(0,0,1);
  63. glVertex3f( 0.9, 0.0, -30.0);
  64. glColor3f(1,0,0);
  65. glVertex3f( 0.9, 0.9, -30.0);
  66. glColor3f(0,1,0);
  67. glVertex3f(-0.9, 0.0, -30.0);
  68. glEnd();
  69. glFlush();
  70. }
  71. int main(int argc, char **argv)
  72. {
  73. GLenum type;
  74. glutInit(&argc, argv);
  75. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  76. type = GLUT_RGB | GLUT_SINGLE;
  77. glutInitDisplayMode(type);
  78. if (glutCreateWindow("First Tri") == GL_FALSE) {
  79. exit(1);
  80. }
  81. glewInit();
  82. Init();
  83. glutReshapeFunc(Reshape);
  84. glutKeyboardFunc(Key);
  85. glutDisplayFunc(Draw);
  86. glutMainLoop();
  87. return 0;
  88. }