OpenGL Study Notes: The First OpenGL Program Fully Annotated

Operating environment:

CentOS7
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
OpenGL implementation vendor's name: VMware, Inc.
Renderer identifier: Gallium 0.4 on llvmpipe (LLVM 3.9, 256 bits)
Version number of OpenGL implementation: 2.1 Mesa 17.0.1
OGLU tool library version: 1.3

Source code:

/**
 * "OpenGL Introductory Tutorial"
 * The first OpenGL program
 */
#include <GL/glut.h>

void myDisplay(void)
{
    /* clear: color */
    glClear(GL_COLOR_BUFFER_BIT);
    /* draw a rectangle */
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    /* Ensure that the preceding OpenGL is executed immediately, without waiting*/
    glFlush();
}

int main(int argc, char *argv[])
{
    /*initialization*/
    glutInit(&argc, argv);
    /* Set display mode: RGB color, single buffer */
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    /* Set to the center of the window */
    glutInitWindowPosition (100, 100);
    /* set window size */
    glutInitWindowSize (400, 400);
    /* create window */
    glutCreateWindow("The first OpenGL program");
    /* set a function */
    glutDisplayFunc(&myDisplay);
    /* Do a message loop */
    glutMainLoop();
    return 0;
}

Compile and run:

$ make
gcc test.c -lGL -lglut -lGLU -lXmu -Bstatic -Bdyanmic
./a.out

result:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325853732&siteId=291194637