+ All Categories
Home > Documents > my GL notes

my GL notes

Date post: 03-Apr-2018
Category:
Upload: sai-ram-prasad-reddy
View: 225 times
Download: 0 times
Share this document with a friend

of 23

Transcript
  • 7/28/2019 my GL notes

    1/23

    glutInit

    glutInit is used to initialize the GLUT library.

    Usage

    void glutInit(int *argcp, char **argv);

    argcpA pointer to the program's unmodifiedargc variable from main.

    argvThe program's unmodifiedargv variable from main.

    Description

    glutInit will initialize the GLUT library and negotiate a session with the windowsystem.

  • 7/28/2019 my GL notes

    2/23

    glutInitDisplayMode

    glutInitDisplayMode sets the initial display mode.

    Usage

    void glutInitDisplayMode(unsigned int mode);mode

    Display mode, normally the bitwise OR-ing of GLUT display mode bitmasks. See values below:

    GLUT_RGBABit mask to select an RGBA mode window. This is the default if

    neitherGLUT_RGBA norGLUT_INDEX are specified.GLUT_RGB

    An alias forGLUT_RGBA.

    GLUT_INDEXBit mask to select a color index mode window. This overrides GLUT_RGBA if itis also specified.

    GLUT_SINGLEBit mask to select a single buffered window. This is the default if

    neitherGLUT_DOUBLE orGLUT_SINGLE are specified.GLUT_DOUBLE

    Bit mask to select a double buffered window. This overrides GLUT_SINGLE if

    it is also specified.GLUT_DEPTH

    Bit mask to select a window with a depth buffer.

    Description

    The initial display mode is used when creating top-level windows, subwindows,and overlays to determine the OpenGL display mode for the to-be-created windowor overlay.

  • 7/28/2019 my GL notes

    3/23

    glutInitWindowPosition, glutInitWindowSize

    glutInitWindowPosition and glutInitWindowSize set the initial windowposition andsize respectively.

    void glutInitWindowSize(int width, int height);

    void glutInitWindowPosition(int x, int y);width

    Width in pixels.height

    Height in pixels.x

    Window X location in pixels.y

    Window Y location in pixels.

    glutCreateWindow

    glutCreateWindow creates a top-level window.

    Usage

    int glutCreateWindow(char *name);name

    ASCII character string for use as window name.

    DescriptionglutCreateWindow creates a top-level window. The name will beprovided to the window system as the window's name. The intent is that the

    window system will label the window with the name.

    Implicitly, the current window is set to the newly created window.

  • 7/28/2019 my GL notes

    4/23

    glutDisplayFunc

    glutDisplayFunc sets the display callback for the current window.

    Usage

    void glutDisplayFunc(void (*func)(void));func

    The new display callback function.

    Description

    glutDisplayFunc sets the display callback for the current window. When GLUT

    determines that the normal plane for the window needs to be redisplayed, thedisplay callback for the window is called. Before the callback, the current

    window is set to the window needing to be redisplayed and (if no overlay displaycallback is registered) the layer in use is set to the normal plane. The displaycallback is called with no parameters. The entire normal plane region should be

    redisplayed in response to the callback (this includes ancillary buffers if yourprogram depends on their state).

  • 7/28/2019 my GL notes

    5/23

    glutMainLoop

    glutMainLoop enters the GLUT event processing loop.

    Usage

    void glutMainLoop(void);

    Description

    glutMainLoop enters the GLUT event processing loop. This routine should becalled at most once in a GLUT program. Once called, this routine will never return.It will call as necessary any callbacks that have been registered.

  • 7/28/2019 my GL notes

    6/23

    glutReshapeFunc

    glutReshapeFunc sets the reshape callback for the current window.

    Usage

    void glutReshapeFunc(void (*func)(int width, int height));func

    The new reshape callback function.

    Description

    glutReshapeFunc sets the reshape callback for the current window. The reshape

    callback is triggered when a window is reshaped. A reshape callback is alsotriggered immediately before a window's first display callback after a window is

    created or whenever an overlay for the window is established.The width and height parameters of the callback specify the new window size in

    pixels. Before the callback, the current windowis set to the window that has beenreshaped.

  • 7/28/2019 my GL notes

    7/23

    Name

    glClearColor specify clear values for the color buffers

    C Specificationvoid glClearColor( GLfloat red,

    GLfloat green,

    GLfloat blue,

    GLfloat alpha);

    Parameters

    red, green, blue, alpha

    Specify the red, green, blue, and alpha values used when the color buffers are cleared. Theinitial values are all 0.

    Description

    glClearColor specifies the red, green, blue, and alpha values used byglClearto clear the color

    buffers. Values specified by glClearColor are clamped to the range 0 1 .

    http://www.opengl.org/sdk/docs/man/xhtml/glClear.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glClear.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glClear.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glClear.xml
  • 7/28/2019 my GL notes

    8/23

    Name

    glClear clear buffers to preset values

    C Specificationvoid glClear(GLbitfield mask);

    Parameters

    mask

    Bitwise OR of masks that indicate the buffers to be cleared. The three masksare GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.

    Description

    glClear sets the bitplane area of the window to values previously selected

    by glClearColor, glClearDepth, and glClearStencil. Multiple color buffers can be cleared

    simultaneously by selecting more than one buffer at a time usingglDrawBuffer.

    lClear takes a single argument that is the bitwise OR of several values indicating which buffer is to

    be cleared.

    The values are as follows:

    GL_COLOR_BUFFER_BIT

    Indicates the buffers currently enabled for color writing.

    GL_DEPTH_BUFFER_BIT

    Indicates the depth 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.

    http://www.opengl.org/sdk/docs/man/xhtml/glDrawBuffer.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glDrawBuffer.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glDrawBuffer.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glDrawBuffer.xml
  • 7/28/2019 my GL notes

    9/23

    glColor3f() takes 3 arguments: the red, green and blue components of the color you want. After you

    use glColor3f, everything you draw will be in that color. For example, consider this display function:

  • 7/28/2019 my GL notes

    10/23

    Name

    glBegin delimit the vertices of a primitive or a group of like primitives

    C Specificationvoid glBegin(GLenum mode);

    Parameters

    mode

    Specifies the primitive or primitives that will be created from vertices

    presented between glBegin and the subsequentglEnd. Ten symbolic

    constants areaccepted: GL_POINTS, GL_LINES, GL_LINE_STRIP,GL_LINE_LOOP, GL_TRIANGLES, G

    L_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP,and GL_POLYGON.

    C Specification

    void glEnd(void);

    DescriptionglBegin andglEnddelimit the vertices that define a primitive or a group of like

    primitives. glBegin accepts a single argument that specifies in which of ten waysthe vertices are interpreted. Taking n as an integer count starting at one, and N asthe total number of vertices specified, the interpretations are as follows:

    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 2 n -

    1 and 2 n 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

    http://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xml
  • 7/28/2019 my GL notes

    11/23

    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 3 n -

    2 , 3 n - 1 , and 3 n define triangle n. N 3 triangles are drawn.

    GL_TRIANGLE_STRIP

    Draws a connected group of triangles. One triangle is defined for eachvertex 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 + 2define

    triangle n. N - 2 triangles are drawn.

    GL_TRIANGLE_FAN

    Draws a connected group of triangles. One triangle is defined for eachvertex 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 definequadrilateral 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 -

    1quadrilaterals are drawn. Note that the order in which vertices are used toconstruct 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.

  • 7/28/2019 my GL notes

    12/23

    Name

    glVertex specify a vertex

    C Specificationvoid glVertex2s(GLshort ,

    GLshort );void glVertex2i(GLint ,

    GLint );void glVertex2f(GLfloat ,

    GLfloat );void glVertex2d(GLdouble ,

    GLdouble );void glVertex3s(GLshort ,

    GLshort ,

    GLshort );void glVertex3i(GLint ,

    GLint ,

    GLint );void glVertex3f(GLfloat ,

    GLfloat ,

    GLfloat );void glVertex3d(GLdouble ,

    GLdouble ,

    GLdouble );void glVertex4s(GLshort ,

    GLshort ,

    GLshort ,

    GLshort w);void glVertex4i(GLint ,

    GLint ,

    GLint ,

    GLint w);void glVertex4f(GLfloat ,

    GLfloat ,

    GLfloat ,GLfloat w);

    void glVertex4d(GLdouble ,

    GLdouble ,

    GLdouble ,

    GLdouble w);

    Parameters

    x, y, z, w

  • 7/28/2019 my GL notes

    13/23

    Specifyx,y,z, and w coordinates of a vertex. Not all parameters are present

    in all forms of the command.

    C Specification

    void glVertex2sv(const GLshort * v);void glVertex2iv(const GLint * v);void glVertex2fv(const GLfloat * v);void glVertex2dv(const GLdouble * v);void glVertex3sv(const GLshort * v);void glVertex3iv(const GLint * v);void glVertex3fv(const GLfloat * v);void glVertex3dv(const GLdouble * v);void glVertex4sv(const GLshort * v);void glVertex4iv(const GLint * v);void glVertex4fv(const GLfloat * v);void glVertex4dv(const GLdouble * v);

    Parameters

    v

    Specifies a pointer to an array of two, three, or four elements. The elementsof a two-element array are x and y; of a three-element array, x, y, and z; and

    of a four-element array, x, y, z, and w.

    Description

    glVertex commands are used withinglBegin/glEndpairs to specify point, line, andpolygon vertices. The current color, normal, texture coordinates, and fogcoordinate are associated with the vertex when glVertex is called.

    When only x and y are specified, z defaults to 0 and w defaults to 1. When x, y,and z are specified, w defaults to 1.

    http://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glEnd.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml
  • 7/28/2019 my GL notes

    14/23

    glutSwapBuffers

    glutSwapBuffers swaps the buffers of the current window if double buffered.

    Usage

    void glutSwapBuffers(void);

    Description

    Performs a buffer swap on the layer in use for the current window.

    Specifically, glutSwapBuffers promotes the contents of the back buffer of the layerin use of the current window to become the contents of the front buffer. The

    contents of the back buffer then become undefined. The update typically takes

    place during the vertical retrace of the monitor, rather than immediatelyafterglutSwapBuffers is called.

    An implicit glFlush is done by glutSwapBuffers before it returns.

    glFlush force execution of GL commands in finite time

    C Specification

    void glFlush(void);

    Description

    Different GL implementations buffer commands in several different locations, including networkbuffers and the graphics accelerator itself. glFlush empties all of these buffers, causing all issued

    commands to be executed as quickly as they are accepted by the actual rendering engine. Thoughthis execution may not be completed in any particular time period, it does complete in finite time.

    Because any GL program might be executed over a network, or on an accelerator that buffers

    commands, all programs should call glFlush whenever they count on having all of their previouslyissued commands completed. For example, call glFlush before waiting for user input that depends

    on the generated image.

  • 7/28/2019 my GL notes

    15/23

    glViewport set the viewport

    C Specification

    void glViewport( GLint x,

    GLint y,

    GLsizei width,

    GLsizei height);

    Parameters

    x, y

    Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).

    width, height

    Specify the width and height of the viewport. When a GL context is first attached to a

    window, width and heightare set to the dimensions of that window.

    Description

    glViewport specifies the affine transformation of x and y from normalized device coordinates to

    window coordinates. Let x nd y nd be normalized device coordinates. Then the window

    coordinates x w y w are computed as follows:

    x w = x nd + 1 width 2 + x

    y w = y nd + 1 height 2 + y

    Viewport width and height are silently clamped to a range that depends on the implementation. To

    query this range, callglGetwith argument GL_MAX_VIEWPORT_DIMS.

    http://www.opengl.org/sdk/docs/man/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man/xhtml/glGet.xml
  • 7/28/2019 my GL notes

    16/23

    glMatrixMode specify which matrix is the current matrix

    C Specification

    void glMatrixMode(GLenum mode)

    ;

    Parameters

    mode

    Specifies which matrix stack is the target for subsequent matrix operations.

    Three values are accepted: GL_MODELVIEW, GL_PROJECTION, and GL_TEXTURE.

    The initial value is GL_MODELVIEW. Additionally, if theARB_imaging extension

    is supported, GL_COLOR is also accepted.

    Description

    glMatrixMode sets the current matrix mode. mode can assume one of four values:

    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,callglGetwith argument GL_MATRIX_MODE. The initial value is GL_MODELVIEW.

    http://www.opengl.org/sdk/docs/man2/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glGet.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glGet.xml
  • 7/28/2019 my GL notes

    17/23

    NAMEglLoadIdentity - replace the current matrix with theidentity matrix

    CSPECIFICATION

    void glLoadIdentity( void )

    DESCRIPTIONglLoadIdentity replaces the current matrix with the identitymatrix. It is semantically equivalent to callingglLoadMatrix with the identity matrix

    ( 1 0 0 0 )| || 0 1 0 0 || 0 0 1 0 |

    | |( 0 0 0 1 )

    but in some cases it is more efficient.

  • 7/28/2019 my GL notes

    18/23

    gluLookAt define a viewing transformation

    C Specification

    void gluLookAt(GLdouble eyeX,

    GLdouble eyeY,

    GLdouble eyeZ,

    GLdouble centerX,

    GLdouble centerY,

    GLdouble centerZ,

    GLdouble upX,

    GLdouble upY,

    GLdouble upZ);

    Parameters

    eyeX, eyeY, eyeZ

    Specifies the position of the eye point.

    centerX, centerY, centerZ

    Specifies the position of the reference point.

    upX, upY, upZ

    Specifies the direction of the up vector.

    Description

    gluLookAt creates a viewing matrix derived from an eye point, a reference point

    indicating the center of the scene, and an UPvector.

    The matrix maps the reference point to the negativezaxis and the eye point to theorigin. When a typical projection matrix is used, the center of the scene thereforemaps to the center of the viewport. Similarly, the direction described by

    the UPvector projected onto the viewing plane is mapped to the positivey axis so

  • 7/28/2019 my GL notes

    19/23

    that it points upward in the viewport. The UPvector must not be parallel to the line

    of sight from the eye point to the reference point.

    Let

    F = centerX - eyeX centerY - eyeY centerZ - eyeZ

    Let UPbe the vector upX upY upZ .

    Then normalize as follows:

    f = F F

    UP = UP UP

    Finally, let s = f UP , and u = s f .

    M is then constructed as follows:

    M = s 0 s 1 s 2 0 u 0 u 1 u 2 0 - f 0 - f 1 - f 2 0 0 0 0 1

    and gluLookAt is equivalent to

    glMultMatrixf(M);glTranslated(-eyex, -eyey, -eyez);

  • 7/28/2019 my GL notes

    20/23

    gluPerspective set up a perspective projection matrix

    C Specification

    void gluPerspective(GLdouble ovy,

    GLdouble aspect,

    GLdouble zNear,

    GLdouble zFar);

    Parameters

    fovy

    Specifies the field of view angle, in degrees, in they direction.

    aspect

    Specifies the aspect ratio that determines the field of view in the x direction.The aspect ratio is the ratio ofx (width) toy (height).

    zNear

    Specifies the distance from the viewer to the near clipping plane (alwayspositive).

    zFar

    Specifies the distance from the viewer to the far clipping plane (always

    positive).

    Description

    gluPerspective specifies a viewing frustum into the world coordinate system. In

    general, the aspect ratio in gluPerspective should match the aspect ratio of the

    associated viewport. For example, aspect = 2.0 means the viewer's angle of view istwice as wide inx as it is iny. If the viewport is twice as wide as it is tall, it

    displays the image without distortion.

    The matrix generated by gluPerspective is multipled by the current matrix, just asifglMultMatrixwere called with the generated matrix. To load the perspectivematrix onto the current matrix stack instead, precede the call

    to gluPerspective with a call toglLoadIdentity.

    http://www.opengl.org/sdk/docs/man2/xhtml/glMultMatrix.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glMultMatrix.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glMultMatrix.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glLoadIdentity.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glLoadIdentity.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glLoadIdentity.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glLoadIdentity.xmlhttp://www.opengl.org/sdk/docs/man2/xhtml/glMultMatrix.xml
  • 7/28/2019 my GL notes

    21/23

    Givenfdefined as follows:

    f = cotangent fovy 2

    The generated matrix is

    f aspect 0 0 0 0 f 0 0 0 0 zFar + zNear zNear - zFar 2 zFar zNear zNear -

    zFar 0 0 -1 0

  • 7/28/2019 my GL notes

    22/23

    gluOrtho2D define a 2D orthographic projection matrix

    C Specification

    void gluOrtho2D(GLdouble left,

    GLdouble right,

    GLdouble bottom,

    GLdouble top);

    Parameters

    left, right

    Specify the coordinates for the left and right vertical clipping planes.

    bottom, top

    Specify the coordinates for the bottom and top horizontal clipping planes.

    Description

    gluOrtho2D sets up a two-dimensional orthographic viewing region.

  • 7/28/2019 my GL notes

    23/23


Recommended