2 /* Copyright (c) Mark J. Kilgard, 1996. */
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
8 /* This program is a response to a question posed by Gil Colgate
9 <gcolgate@sirius.com> about how lengthy a program is required using
10 OpenGL compared to using Direct3D immediate mode to "draw a
11 triangle at screen coordinates 0,0, to 200,200 to 20,200, and I
12 want it to be blue at the top vertex, red at the left vertex, and
13 green at the right vertex". I'm not sure how long the Direct3D
14 program is; Gil has used Direct3D and his guess is "about 3000
17 /* X compile line: cc -o simple simple.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */
22 #define DEBUG_FUNC_CALLED() printf("function: %s called\n", __func__)
27 /* Because Gil specified "screen coordinates" (presumably with an
28 upper-left origin), this short bit of code sets up the coordinate
29 system to correspond to actual window coodrinates. This code
30 wouldn't be required if you chose a (more typical in 3D) abstract
35 glViewport(0, 0, w
, h
); /* Establish viewing area to cover entire window. */
36 glMatrixMode(GL_PROJECTION
); /* Start modifying the projection matrix. */
37 glLoadIdentity(); /* Reset project matrix. */
38 //glOrtho(0, w, 0, h, -1, 1); /* Map abstract coords directly to window coords. */
39 glScalef(1, -1, 1); /* Invert Y axis so increasing Y goes down. */
40 glTranslatef(0, -h
, 0); /* Shift origin up to upper-left corner. */
48 glClear(GL_COLOR_BUFFER_BIT
);
49 glBegin(GL_TRIANGLES
);
50 glColor3f(0.0, 0.0, 1.0); /* blue */
51 glVertex3f(100, 100, 0);
52 glColor3f(0.0, 1.0, 0.0); /* green */
53 glVertex3f(50, 200, 0);
54 glColor3f(1.0, 0.0, 0.0); /* red */
55 glVertex3f(150, 200, 0.0);
57 glFlush(); /* Single buffered, so needs a flush. */
60 int main(int argc
, char **argv
)
62 glutInit(&argc
, argv
);
63 glutCreateWindow("single triangle");
64 glutDisplayFunc(display
);
65 glutReshapeFunc(reshape
);
68 return 0; /* ANSI C requires main to return int. */