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.

vp-tri-cb-pos.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <GL/glew.h>
  8. #include <GL/glut.h>
  9. GLenum doubleBuffer;
  10. static void Init(void)
  11. {
  12. GLint errno;
  13. GLuint prognum;
  14. static const char *prog1 =
  15. "!!ARBvp1.0\n"
  16. "PARAM Emission = state.material.emission; \n"
  17. "PARAM Ambient = state.material.ambient; \n"
  18. "PARAM Diffuse = state.material.diffuse; \n"
  19. "PARAM Specular = state.material.specular; \n"
  20. "DP4 result.position.x, Ambient, vertex.position;\n"
  21. "DP4 result.position.y, Diffuse, vertex.position;\n"
  22. "DP4 result.position.z, Specular, vertex.position;\n"
  23. "DP4 result.position.w, Emission, vertex.position;\n"
  24. "MOV result.color, vertex.color;\n"
  25. "END\n";
  26. const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
  27. const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
  28. const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
  29. const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
  30. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
  31. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
  32. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
  33. glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
  34. glGenProgramsARB(1, &prognum);
  35. glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
  36. glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  37. strlen(prog1), (const GLubyte *) prog1);
  38. assert(glIsProgramARB(prognum));
  39. errno = glGetError();
  40. printf("glGetError = %d\n", errno);
  41. if (errno != GL_NO_ERROR)
  42. {
  43. GLint errorpos;
  44. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  45. printf("errorpos: %d\n", errorpos);
  46. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  47. }
  48. glEnable(GL_VERTEX_PROGRAM_NV);
  49. }
  50. static void Reshape(int width, int height)
  51. {
  52. glViewport(0, 0, (GLint)width, (GLint)height);
  53. glMatrixMode(GL_PROJECTION);
  54. glLoadIdentity();
  55. /* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
  56. glMatrixMode(GL_MODELVIEW);
  57. }
  58. static void Key(unsigned char key, int x, int y)
  59. {
  60. switch (key) {
  61. case 27:
  62. exit(1);
  63. default:
  64. return;
  65. }
  66. glutPostRedisplay();
  67. }
  68. static void Draw(void)
  69. {
  70. glClear(GL_COLOR_BUFFER_BIT);
  71. glBegin(GL_TRIANGLES);
  72. glColor3f(0,0,.7);
  73. glVertex3f( 0.9, -0.9, -0.0);
  74. glColor3f(.8,0,0);
  75. glVertex3f( 0.9, 0.9, -0.0);
  76. glColor3f(0,.9,0);
  77. glVertex3f(-0.9, 0.0, -0.0);
  78. glEnd();
  79. glFlush();
  80. if (doubleBuffer) {
  81. glutSwapBuffers();
  82. }
  83. }
  84. static GLenum Args(int argc, char **argv)
  85. {
  86. GLint i;
  87. doubleBuffer = GL_FALSE;
  88. for (i = 1; i < argc; i++) {
  89. if (strcmp(argv[i], "-sb") == 0) {
  90. doubleBuffer = GL_FALSE;
  91. } else if (strcmp(argv[i], "-db") == 0) {
  92. doubleBuffer = GL_TRUE;
  93. } else {
  94. fprintf(stderr, "%s (Bad option).\n", argv[i]);
  95. return GL_FALSE;
  96. }
  97. }
  98. return GL_TRUE;
  99. }
  100. int main(int argc, char **argv)
  101. {
  102. GLenum type;
  103. glutInit(&argc, argv);
  104. if (Args(argc, argv) == GL_FALSE) {
  105. exit(1);
  106. }
  107. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  108. type = GLUT_RGB | GLUT_ALPHA;
  109. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  110. glutInitDisplayMode(type);
  111. if (glutCreateWindow("First Tri") == GL_FALSE) {
  112. exit(1);
  113. }
  114. glewInit();
  115. Init();
  116. glutReshapeFunc(Reshape);
  117. glutKeyboardFunc(Key);
  118. glutDisplayFunc(Draw);
  119. glutMainLoop();
  120. return 0;
  121. }