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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <GL/glew.h>
  5. #include <GL/glut.h>
  6. static void Init( void )
  7. {
  8. /* scale of 10.0 gives me a visible result on nv hardware.
  9. */
  10. static const char *modulate2D =
  11. "!!ARBfp1.0\n"
  12. "TEMP R0;\n"
  13. "MUL R0, fragment.position.z, {10.0}.x;\n"
  14. "MOV result.color, R0; \n"
  15. "END"
  16. ;
  17. GLuint modulateProg;
  18. if (!GLEW_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. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  32. glClearColor(.3, .3, .3, 0);
  33. }
  34. static void Reshape(int width, int height)
  35. {
  36. glViewport(0, 0, (GLint)width, (GLint)height);
  37. glMatrixMode(GL_PROJECTION);
  38. glLoadIdentity();
  39. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  40. glMatrixMode(GL_MODELVIEW);
  41. }
  42. static void Key(unsigned char key, int x, int y)
  43. {
  44. switch (key) {
  45. case 27:
  46. exit(1);
  47. default:
  48. break;
  49. }
  50. glutPostRedisplay();
  51. }
  52. static void Draw(void)
  53. {
  54. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  55. glEnable(GL_DEPTH_TEST);
  56. glBegin(GL_TRIANGLES);
  57. glColor3f(0,0,1);
  58. glVertex3f( 0.9, -0.9, -30.0);
  59. glVertex3f( 0.9, 0.9, -30.0);
  60. glVertex3f(-0.9, 0.0, -30.0);
  61. glColor3f(0,1,0);
  62. glVertex3f(-0.9, -0.9, -40.0);
  63. glVertex3f(-0.9, 0.9, -40.0);
  64. glVertex3f( 0.9, 0.0, -25.0);
  65. glEnd();
  66. glFlush();
  67. }
  68. int main(int argc, char **argv)
  69. {
  70. GLenum type;
  71. glutInit(&argc, argv);
  72. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  73. type = GLUT_RGB | GLUT_DEPTH;
  74. type |= GLUT_SINGLE;
  75. glutInitDisplayMode(type);
  76. if (glutCreateWindow("First Tri") == GL_FALSE) {
  77. exit(1);
  78. }
  79. glewInit();
  80. Init();
  81. glutReshapeFunc(Reshape);
  82. glutKeyboardFunc(Key);
  83. glutDisplayFunc(Draw);
  84. glutMainLoop();
  85. return 0;
  86. }