To prepare data

  • GLTools
  • glew
  • libGLTools.a

Information has been packed in Baidu cloud disk password: PQVQ, if necessary.

hands-on

Open the Xcode create project and select macOS->App

Drag the prepared data into the project

Add the “include” folder path in Build Settings-> Header Search Paths

Create the main CPP

Add two system libraries, Opengl. framework and GLUT. Framework

Test environment: Open main. CPP and copy the code:

#include "GLTools.h"
#include "GLShaderManager.h"
#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endifGLBatch triangleBatch; GLShaderManager shaderManager; Void ChangeSize(int w,int h) {glViewport(0,0, w, h); } // Set void once for the programSetupRC() {// set the background color to glClearColor(0.0f,0.0f,1.0f,1.0f); / / initialize shader manager shaderManager. InitializeStockShaders (); // Set the triangle, where the array vVert contains x,y, cartesian pairs of all 3 vertices. GLfloatF vVerts [] = {0.5, 0.0 f to 0.0 f to 0.5 f to 0.0 f to 0.0 f to 0.0 f to 0.5 f to 0.0 f,}; // Triangles.Begin(GL_TRIANGLES,3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.End(); } // Start rendering void RenderScene(void) {// Clear a specific buffer or set of buffers glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); // Set a set of floating point numbers to represent red GLfloatVRed [] = {0.0 1.0 f, f, f 0.0, 1.0} f; // Pass to the storage shader, GLT_SHADER_IDENTITY shader, This shader is only using the specified color on the screen in a cartesian coordinates by default the first rendering geometry shaderManager. UseStockShader (GLT_SHADER_IDENTITY vRed); // Submit the shader triangleBatch.draw (); GlutSwapBuffers (); } int main(int argc,char* argv[]) {// Set the current working directory, for MAC OS X gltSetWorkingDirectory(argv[0]); // Initialize GLUT Library glutInit(&argc, argv); /* Initialize the double buffering window, The symbols GLUT_DOUBLE, GLUT_RGBA, GLUT_DEPTH and GLUT_STENCIL respectively refer to the double buffer window, RGBA color mode, depth test and template buffer */ glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); GlutInitWindowSize (800,600); glutCreateWindow("Triangle"); GlutReshapeFunc (ChangeSize); glutDisplayFunc(RenderScene); // There are no problems with driver initialization. GLenum err = glewInit();if(GLEW_OK ! = err) { fprintf(stderr,"glew error:%s\n",glewGetErrorString(err));
        return1; // call SetupRC SetupRC(); glutMainLoop();return 0;
}
Copy the code

Run! rendering

The last

Warning: Build Settings -> Deprecated Functions -> NO

Above, environment setup is complete. Start OpenGL romantic journey ~