0%

GL/glut.h

Functions

Initialization

glutInit()

glutInit(&argc, argv); Initialize the GLUT library.

  • argc: A pointer to the program’s unmodified argc variable from main. Upon return, the value pointed to by argc will be updated, because glutInit extracts any command line options intended for the GLUT library.

  • argv: The program’s unmodified argv variable from main. Like argc, the data for argv will be updated because glutInit extracts any command line options understood by the GLUT library.

glutInitDisplayMode()

void glutInitDisplayMode(MODE); sets the initial display mode.

MODE

  • GLUT_RGBA / GLUT_RGB

Bit mask to select an RGBA mode window. This is the default if neither GLUT_RGBA nor GLUT_INDEX are specified.

  • GLUT_INDEX

Bit mask to select a color index mode window. This overrides GLUT_RGBA if it is also specified.

  • GLUT_SINGLE

Bit mask to select a single buffered window. This is the default if neither GLUT_DOUBLE or GLUT_SINGLE are specified.

  • GLUT_DOUBLE

Bit mask to select a double buffered window. This overrides GLUT_SINGLE if it is also specified.

  • GLUT_ACCUM

Bit mask to select a window with an accumulation buffer.

  • GLUT_ALPHA

Bit mask to select a window with an alpha component to the color buffer(s).

  • GLUT_DEPTH

Bit mask to select a window with a depth buffer.

  • GLUT_STENCIL

Bit mask to select a window with a stencil buffer.

  • GLUT_MULTISAMPLE

Bit mask to select a window with multisampling support. If multisampling is not available, a non-multisampling window will automatically be chosen. Note: both the OpenGL client-side and server-side implementations must support the GLX_SAMPLE_SGIS extension for multisampling to be available.

  • GLUT_STEREO

Bit mask to select a stereo window.

  • GLUT_LUMINANCE

Bit mask to select a window with a “luminance’’ color model. This model provides the functionality of OpenGL’s RGBA color model, but the green and blue components are not maintained in the frame buffer. Instead each pixel’s red component is converted to an index between zero and glutGet(GLUT_WINDOW_COLORMAP_SIZE)-1 and looked up in a per-window color map to determine the color of pixels within the window. The initial colormap of GLUT_LUMINANCE windows is initialized to be a linear gray ramp, but can be modified with GLUT’s colormap routines.

glutInitWindowSize(), glutInitWindowPosition()

glutInitWindowSize(int width, int height);

glutInitWindowPosition(int x, int y);

glutCreateWindow()

glutCreateWindow(string window_name);

DIsplay

glclear(), glClearColor()

void glclear(GLbitfield mask);

  • GL_COLOR_BUFFER_BIT

    Indicates the buffers currently enabled for color writing.

  • GL_DEPTH_BUFFER_BIT

    Indicates the depth buffer.

  • GL_ACCUM_BUFFER_BIT

    Indicates the accumulation buffer.

  • GL_STENCIL_BUFFER_BIT

    Indicates the stencil buffer.

The value to which each buffer is cleared depends on the setting of the clear value for that buffer.

void glClearColor(red, green, blue, (alpha))

glClearColor(, , ,) specifies the red, green, blue, and alpha values used by glClear(, , , ) to clear the color buffers. Values specified by glClearColor(, , ,) are clamped to the range 0 1 .

glColor(red, green, blue, (alpha))

set the current color.

void glColor3b(byte, byte, byte);
void glColor3s(short, short, short);
void glColor3i(int, int, int);
void glColor3f(float, float, float);
void glColor3d(double, double, double);
void glColor3ub(ubyte, ubyte, ubyte);
void glColor3us(ushort, ushort, ushort);
void glColor3ui(uint, uint, uint);
-------
void glColor4b(byte, byte, byte, byte);
...

glBegin(), glEnd(), glFlush()

description

void glBegin(GLenum mode);
...//(do something)
void glEnd();

Specifies the primitive or primitives that will be created from vertices presented between glBegin and the subsequent glEnd.

mode

GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON.

  • GL_POINTS

Treats each vertex as a single point. Vertex $n$ defines point $n$. $N$ points are drawn.

  • GL_LINES

Treats each pair of vertices as an independent line segment. Vertices $2n - 1$ and $2n$ define line $n$. $N/2$ lines are drawn.

  • GL_LINE_STRIP

Draws a connected group of line segments from the first vertex to the last. Vertices $n$ and $n + 1$ define line $n$. $N - 1$ lines are drawn.

  • GL_LINE_LOOP

Draws a connected group of line segments from the first vertex to the last, then back to the first. Vertices $n$ and $n + 1$ define line $n$. The last line, however, is defined by vertices $N$ and $1$ . $N$ lines are drawn.

  • GL_TRIANGLES

Treats each triplet of vertices as an independent triangle. Vertices $3n - 2$ , $3 n - 1$ , and $3n$ define triangle $n$. $N /3$ triangles are drawn.

  • GL_TRIANGLE_STRIP

Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd $n$, vertices $n$, $n + 1$ , and $n + 2$ define triangle $n$. For even $n$, vertices $n + 1$ , $n$, and $n + 2$ define triangle $n$. $N - 2$ triangles are drawn.

  • GL_TRIANGLE_FAN

Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. Vertices $1$ , $n + 1$ , and $n + 2$ define triangle $n$. $N - 2$ triangles are drawn.

  • GL_QUADS

Treats each group of four vertices as an independent quadrilateral. Vertices $4 ⁢ n - 3$ , $4 ⁢ n - 2$ , $4 ⁢ n - 1$ , and $4 ⁢ n $ define quadrilateral $n$. $N/4$ quadrilaterals are drawn.

  • GL_QUAD_STRIP

Draws a connected group of quadrilaterals. One quadrilateral is defined for each pair of vertices presented after the first pair. Vertices $2 ⁢ n - 1$ , $2 ⁢ n$ , $2 ⁢ n + 2$ , and $2 ⁢ n + 1$ define quadrilateral $n$. $N/2 - 1$ quadrilaterals are drawn. Note that the order in which vertices are used to construct a quadrilateral from strip data is different from that used with independent data.

  • GL_POLYGON

Draws a single, convex polygon. Vertices $1$ through $N$ define this polygon.

glFlush()

Force execution of GL commands in finite time.

glVertex(x, y, z, w, …)

Specify a vertex.

void glVertex2s(short, short);
void glVertex2i(int, int);
void glVertex2f(float, float);
void glVertex2d(double, double);
void glVertex3s(, , );
void glVertex3i(, , );
void glVertex3f(, , );
void glVertex3d(, , );
void glVertex4s(, , , );
void glVertex4i(, , , );
void glVertex4f(, , , );
void glVertex4d(, , , );

glPointSize()

Specify the diameter of rasterized points.

void glPointSize(float size). The initial value is 1.

glMatrixMode()

Specify which matrix is the current matrix.

void glMatrixMode(Glenum mode);

  • GL_MODELVIEW

Applies subsequent matrix operations to the modelview matrix stack.

  • GL_PROJECTION

Applies subsequent matrix operations to the projection matrix stack.

  • GL_TEXTURE

Applies subsequent matrix operations to the texture matrix stack.

  • GL_COLOR

Applies subsequent matrix operations to the color matrix stack.

To find out which matrix stack is currently the target of all matrix operations, call glGet() with argument GL_MATRIX_MODE. The initial value is GL_MODELVIEW.

gluOrtho2D()

Define a 2D orthographic projection matrix.

void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);

glutMouseFunc()

void glutMouseFunc(void (*func)(int button, int state, int x, int y)); sets the mouse callback for the current window.

The button parameter is one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON.

The state parameter is either GLUT_UP or GLUT_DOWN indicating whether the callback was due to a release or press respectively.

Passing NULL to glutMouseFunc disables the generation of mouse callbacks.

reference

https://www.opengl.org/resources/libraries/glut/

https://www.khronos.org/registry/OpenGL-Refpages/