Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

tri-tex.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #define GL_GLEXT_PROTOTYPES
  6. #include <GL/glut.h>
  7. #include "readtex.c"
  8. #define TEXTURE_FILE "../images/girl.rgb"
  9. static void Init( void )
  10. {
  11. static const char *modulate2D =
  12. "!!ARBfp1.0\n"
  13. "TEX result.color, fragment.color, texture[0], 2D; \n"
  14. "END"
  15. ;
  16. GLuint modulateProg;
  17. GLuint Texture;
  18. if (!glutExtensionSupported("GL_ARB_fragment_program")) {
  19. printf("Error: GL_ARB_fragment_program not supported!\n");
  20. exit(1);
  21. }
  22. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  23. /* Setup the fragment program */
  24. glGenProgramsARB(1, &modulateProg);
  25. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
  26. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  27. strlen(modulate2D), (const GLubyte *)modulate2D);
  28. printf("glGetError = 0x%x\n", (int) glGetError());
  29. printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
  30. (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  31. assert(glIsProgramARB(modulateProg));
  32. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  33. /* Load texture */
  34. glGenTextures(1, &Texture);
  35. glBindTexture(GL_TEXTURE_2D, Texture);
  36. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  37. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  38. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  39. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  40. printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
  41. exit(1);
  42. }
  43. /* XXX this enable shouldn't really be needed!!! */
  44. glEnable(GL_TEXTURE_2D);
  45. glClearColor(.3, .3, .3, 0);
  46. }
  47. static void Reshape(int width, int height)
  48. {
  49. glViewport(0, 0, (GLint)width, (GLint)height);
  50. glMatrixMode(GL_PROJECTION);
  51. glLoadIdentity();
  52. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  53. glMatrixMode(GL_MODELVIEW);
  54. }
  55. static void Key(unsigned char key, int x, int y)
  56. {
  57. switch (key) {
  58. case 27:
  59. exit(1);
  60. default:
  61. return;
  62. }
  63. glutPostRedisplay();
  64. }
  65. static void Draw(void)
  66. {
  67. glClear(GL_COLOR_BUFFER_BIT);
  68. glBegin(GL_TRIANGLES);
  69. glColor3f(0,0,1);
  70. /* glTexCoord2f(1, 0); */
  71. glVertex3f( 0.9, -0.9, -30.0);
  72. glColor3f(1,0,0);
  73. /* glTexCoord2f(1, 1); */
  74. glVertex3f( 0.9, 0.9, -30.0);
  75. glColor3f(0,1,0);
  76. /* glTexCoord2f(0, .5); */
  77. glVertex3f(-0.9, 0.0, -30.0);
  78. glEnd();
  79. glFlush();
  80. }
  81. int main(int argc, char **argv)
  82. {
  83. GLenum type;
  84. glutInit(&argc, argv);
  85. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  86. type = GLUT_RGB;
  87. type |= GLUT_SINGLE;
  88. glutInitDisplayMode(type);
  89. if (glutCreateWindow("First Tri") == GL_FALSE) {
  90. exit(1);
  91. }
  92. Init();
  93. glutReshapeFunc(Reshape);
  94. glutKeyboardFunc(Key);
  95. glutDisplayFunc(Draw);
  96. glutMainLoop();
  97. return 0;
  98. }