Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

tri-flat.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  9. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  10. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  11. glClearColor(0.5, 0.5, 0.5, 0.0);
  12. }
  13. static void Reshape(int width, int height)
  14. {
  15. glViewport(0, 0, (GLint)width, (GLint)height);
  16. glMatrixMode(GL_PROJECTION);
  17. glLoadIdentity();
  18. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  19. glMatrixMode(GL_MODELVIEW);
  20. }
  21. static void Key(unsigned char key, int x, int y)
  22. {
  23. switch (key) {
  24. case 27:
  25. exit(1);
  26. default:
  27. return;
  28. }
  29. glutPostRedisplay();
  30. }
  31. static void Draw(void)
  32. {
  33. glClear(GL_COLOR_BUFFER_BIT);
  34. glShadeModel(GL_FLAT);
  35. glBegin(GL_TRIANGLES);
  36. glColor3f(0,0,1);
  37. glVertex3f( 0.9, -0.9, -30.0);
  38. glColor3f(1,0,0);
  39. glVertex3f( 0.9, 0.9, -30.0);
  40. glColor3f(0,1,0);
  41. glVertex3f(-0.9, 0.0, -30.0);
  42. glEnd();
  43. glFlush();
  44. /* Exit after first frame
  45. */
  46. exit(0);
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. GLenum type;
  51. glutInit(&argc, argv);
  52. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  53. type = GLUT_RGB;
  54. type |= GLUT_SINGLE;
  55. glutInitDisplayMode(type);
  56. if (glutCreateWindow("First Tri") == GL_FALSE) {
  57. exit(1);
  58. }
  59. Init();
  60. glutReshapeFunc(Reshape);
  61. glutKeyboardFunc(Key);
  62. glutDisplayFunc(Draw);
  63. glutMainLoop();
  64. return 0;
  65. }