Configuring OpenGL environment on Mac OS

OpenGL environment is configured under Mac OS system
1. Prepare resources
CLToolsglewlibGLTools.
a
file can be downloaded in baidu network backup, link: https://pan.baidu.com/s/13gkpLWjbKSBNFnA-IGo23A password: g3b5
2. Create a project

3. Import the system Framework
Import OpenGL. Framework and Glut. Framework.

4. Add prepared resources
Drag the include file down into the project;
Drag the libgltools.a file into the Framework group under your project;
Add glew.h and gltools.h Paths to Header Search Paths.

5. Delete the unwanted files and create Main.cpp
Delete AppDelegate.swift, ViewController.swift, and if there are any main.m files, delete them as well.
create main.cpp file, do not check “Also create a header file”.

6. Compile
If you encounter a compilation error, import mode from the system library to <; > Change to plain file to introduce "".
test as follows:


#include "GLShaderManager.h"
#include "GLTools.h"
#include <GLUT/GLUT.h>

GLShaderManager shaderManager;

GLBatch triangleBatch;

void changeSize(int w,int h)
{
    glViewport(0, 0, w, h);
}

void RenderScene(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
    
    GLfloat vRed[] = {1.0,1.00,0.0,0.5f};
    
    shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed);
    
    triangleBatch.Draw();
    
    glutSwapBuffers();
}

void setupRC()
{
    glClearColor(0.3f, 1.0f, 1.0f, 1);
    
    shaderManager.InitializeStockShaders();
    
    GLfloat vVerts[] = {
        0.0f,0.8f,0.0f,
        0.5f,0.0f,0.0f,
        -0.5f,0.0f,0.0f
    };
    
    triangleBatch.Begin(GL_TRIANGLES, 3);
    triangleBatch.CopyVertexData3f(vVerts);
    triangleBatch.End();
    
}

int main(int argc,char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);
    glutInitWindowSize(600, 400);
    glutCreateWindow("Triangle");
    glutReshapeFunc(changeSize);
    glutDisplayFunc(RenderScene);
    GLenum status = glewInit();
    if (GLEW_OK != status) {
        
        printf("GLEW Error:%s\n",glewGetErrorString(status));
        return 1;
        
    }
    setupRC();
    glutMainLoop();
 
    return  0;
    
}

Read More: