Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

fptexture.c 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* GL_NV_fragment_program texture test */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <GL/glew.h>
  8. #include <GL/glut.h>
  9. #include "../util/readtex.c"
  10. #define TEXTURE_FILE "../images/girl.rgb"
  11. static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
  12. static void Display( void )
  13. {
  14. glClear( GL_COLOR_BUFFER_BIT );
  15. glPushMatrix();
  16. glRotatef(Xrot, 1.0, 0.0, 0.0);
  17. glRotatef(Yrot, 0.0, 1.0, 0.0);
  18. glRotatef(Zrot, 0.0, 0.0, 1.0);
  19. glBegin(GL_POLYGON);
  20. glColor4f(1.0, 1.0, 1.0, 1); glTexCoord2f(0, 0); glVertex2f(-1, -1);
  21. glColor4f(0.2, 0.2, 1.0, 1); glTexCoord2f(1, 0); glVertex2f( 1, -1);
  22. glColor4f(0.2, 1.0, 0.2, 1); glTexCoord2f(1, 1); glVertex2f( 1, 1);
  23. glColor4f(1.0, 0.2, 0.2, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1);
  24. glEnd();
  25. glPopMatrix();
  26. glutSwapBuffers();
  27. }
  28. static void Reshape( int width, int height )
  29. {
  30. glViewport( 0, 0, width, height );
  31. glMatrixMode( GL_PROJECTION );
  32. glLoadIdentity();
  33. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  34. glMatrixMode( GL_MODELVIEW );
  35. glLoadIdentity();
  36. glTranslatef( 0.0, 0.0, -8.0 );
  37. }
  38. static void SpecialKey( int key, int x, int y )
  39. {
  40. float step = 3.0;
  41. (void) x;
  42. (void) y;
  43. switch (key) {
  44. case GLUT_KEY_UP:
  45. Xrot += step;
  46. break;
  47. case GLUT_KEY_DOWN:
  48. Xrot -= step;
  49. break;
  50. case GLUT_KEY_LEFT:
  51. Yrot += step;
  52. break;
  53. case GLUT_KEY_RIGHT:
  54. Yrot -= step;
  55. break;
  56. }
  57. glutPostRedisplay();
  58. }
  59. static void Key( unsigned char key, int x, int y )
  60. {
  61. (void) x;
  62. (void) y;
  63. switch (key) {
  64. case 27:
  65. exit(0);
  66. break;
  67. }
  68. glutPostRedisplay();
  69. }
  70. static void Init( void )
  71. {
  72. static const char *modulate2D =
  73. "!!FP1.0\n"
  74. "TEX R0, f[TEX0], TEX0, 2D; \n"
  75. "MUL o[COLR], R0, f[COL0]; \n"
  76. "END"
  77. ;
  78. GLuint modulateProg;
  79. GLuint Texture;
  80. if (!glutExtensionSupported("GL_NV_fragment_program")) {
  81. printf("Error: GL_NV_fragment_program not supported!\n");
  82. exit(1);
  83. }
  84. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  85. /* Setup the fragment program */
  86. glGenProgramsNV(1, &modulateProg);
  87. glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg,
  88. strlen(modulate2D),
  89. (const GLubyte *) modulate2D);
  90. printf("glGetError = 0x%x\n", (int) glGetError());
  91. printf("glError(GL_PROGRAM_ERROR_STRING_NV) = %s\n",
  92. (char *) glGetString(GL_PROGRAM_ERROR_STRING_NV));
  93. assert(glIsProgramNV(modulateProg));
  94. glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg);
  95. glEnable(GL_FRAGMENT_PROGRAM_NV);
  96. /* Load texture */
  97. glGenTextures(1, &Texture);
  98. glBindTexture(GL_TEXTURE_2D, Texture);
  99. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  100. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  101. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  102. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  103. printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
  104. exit(1);
  105. }
  106. /* XXX this enable shouldn't really be needed!!! */
  107. glEnable(GL_TEXTURE_2D);
  108. glClearColor(.3, .3, .3, 0);
  109. }
  110. int main( int argc, char *argv[] )
  111. {
  112. glutInit( &argc, argv );
  113. glutInitWindowPosition( 0, 0 );
  114. glutInitWindowSize( 250, 250 );
  115. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  116. glutCreateWindow(argv[0]);
  117. glewInit();
  118. glutReshapeFunc( Reshape );
  119. glutKeyboardFunc( Key );
  120. glutSpecialFunc( SpecialKey );
  121. glutDisplayFunc( Display );
  122. Init();
  123. glutMainLoop();
  124. return 0;
  125. }