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-depthwrite.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define GL_GLEXT_PROTOTYPES
  5. #include <GL/glut.h>
  6. static void Init(void)
  7. {
  8. static const char *modulate2D =
  9. "!!ARBfp1.0\n"
  10. "MUL result.depth.z, fragment.color.z, {.1}.x; \n"
  11. "MOV result.color.xy, fragment.color; \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|GL_DEPTH_BUFFER_BIT);
  52. glEnable(GL_DEPTH_TEST);
  53. glBegin(GL_TRIANGLES);
  54. glColor4f(.8,0,.5,0);
  55. glVertex3f( 0.9, -0.9, -30.0);
  56. glVertex3f( 0.9, 0.9, -30.0);
  57. glVertex3f(-0.9, 0.0, -30.0);
  58. glColor4f(0,.8,.7,0);
  59. glVertex3f(-0.9, -0.9, -40.0);
  60. glColor4f(0,.8,.7,0);
  61. glVertex3f(-0.9, 0.9, -40.0);
  62. glColor4f(0,.8,.3,0);
  63. glVertex3f( 0.9, 0.0, -40.0);
  64. glEnd();
  65. glFlush();
  66. }
  67. int main(int argc, char **argv)
  68. {
  69. glutInit(&argc, argv);
  70. glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
  71. glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE);
  72. if (glutCreateWindow("Depth Test") == GL_FALSE) {
  73. exit(1);
  74. }
  75. Init();
  76. glutReshapeFunc(Reshape);
  77. glutKeyboardFunc(Key);
  78. glutDisplayFunc(Draw);
  79. glutMainLoop();
  80. return 0;
  81. }