Advertisement
Guest User

Wew

a guest
Oct 15th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. /* Copyright (c) Mark J. Kilgard, 1996. */
  2.  
  3. /* This program is freely distributable without licensing fees
  4.    and is provided without guarantee or warrantee expressed or
  5.    implied. This program is -not- in the public domain. */
  6.  
  7. /* This program is a response to a question posed by Gil Colgate
  8.    <gcolgate@sirius.com> about how lengthy a program is required using
  9.    OpenGL compared to using  Direct3D immediate mode to "draw a
  10.    triangle at screen coordinates 0,0, to 200,200 to 20,200, and I
  11.    want it to be blue at the top vertex, red at the left vertex, and
  12.    green at the right vertex".  I'm not sure how long the Direct3D
  13.    program is; Gil has used Direct3D and his guess is "about 3000
  14.    lines of code". */
  15.  
  16. /* X compile line: cc -o simple simple.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */
  17.  
  18. #include <GL/glut.h>
  19.  
  20. void
  21. reshape(int w, int h)
  22. {
  23.   /* Because Gil specified "screen coordinates" (presumably with an
  24.      upper-left origin), this short bit of code sets up the coordinate
  25.      system to correspond to actual window coodrinates.  This code
  26.      wouldn't be required if you chose a (more typical in 3D) abstract
  27.      coordinate system. */
  28.  
  29.   glViewport(0, 0, w, h);       /* Establish viewing area to cover entire window. */
  30.   glMatrixMode(GL_PROJECTION);  /* Start modifying the projection matrix. */
  31.   glLoadIdentity();             /* Reset project matrix. */
  32.   glOrtho(0, w, 0, h, -1, 1);   /* Map abstract coords directly to window coords. */
  33.   glScalef(1, -1, 1);           /* Invert Y axis so increasing Y goes down. */
  34.   glTranslatef(0, -h, 0);       /* Shift origin up to upper-left corner. */
  35. }
  36.  
  37. void
  38. display(void)
  39. {
  40.   glClear(GL_COLOR_BUFFER_BIT);
  41.   glBegin(GL_TRIANGLES);
  42.     glColor3f(0.0, 0.0, 1.0);  /* blue */
  43.     glVertex2i(0, 0);
  44.     glColor3f(0.0, 1.0, 0.0);  /* green */
  45.     glVertex2i(200, 200);
  46.     glColor3f(1.0, 0.0, 0.0);  /* red */
  47.     glVertex2i(20, 200);
  48.   glEnd();
  49.   glFlush();  /* Single buffered, so needs a flush. */
  50. }
  51.  
  52. int
  53. main(int argc, char **argv)
  54. {
  55.   glutInit(&argc, argv);
  56.   glutCreateWindow("single triangle");
  57.   glutDisplayFunc(display);
  58.   glutReshapeFunc(reshape);
  59.   glutMainLoop();
  60.   return 0;             /* ANSI C requires main to return int. */
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement