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-frc.c 2.2KB

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