Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tri-swz.c 2.1KB

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