Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

tri-depth2.c 2.4KB

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