My OpenGL thematic learning directory, hope to learn with you exchange progress!

  • OpenGL Learning (I) – Terminology understanding
  • OpenGL learning (2) — Xcode build OpenGL environment
  • OpenGL learning (three) – OpenGL base rendering
  • OpenGL learning (4) – front & back culling and depth testing
  • OpenGL Learning (5) – Cropping and Blending
  • OpenGL Learning (6) – Base textures
  • OpenGL Learning (7) — Summary of basic change Comprehensive Exercise practice
  • OpenGL ES Learning (8)
  • OpenGL learning (nine) — OpenGL ES preliminary exploration (next) GLKit
  • OpenGL learning (10) – GLSL syntax introduction
  • OpenGL learning (11) – using GLSL to load pictures
  • OpenGL learning (12) — OpenGL ES texture flipping strategy comparison

1. Preparation before construction

First of all, the following libraries are needed before building:

  • 1. libGLTools.a
  • 2. CLTools
  • 3. glew

To make it easy for you to download, I have uploaded them to the web disk, which shares the address link password: WI5b

2. Construction begins

1. Create a project

2. Select the Cocoa App type

3. Add a dependency library

Add the dependency Libraries “GLUT. Framework” and “Opengl. framework” to Bulid Phases — Link Binary With Libraries at ➕.

4. Configure the path

(1) Drag the downloaded include folder directly into the project and the libglTools. a static library directly into the Frameworks of the project.

(2) Search for “Header Search” in Build Settings and add “include search Paths” to the “Header Search Paths” folder.

5. Create a main. CPP

Create a file of c++ type, call it main, and uncheck the create header check box.

6. DeleteAppDelegate.h,AppDelegate.m,main.mViewController.hViewController.m

Three, run the test code

If there is an error about the certificate, don’t forget to modify the certificate to “Sign to Run Locally(Ad Hoc Code Sign)”.

Here is a bit of modified test code from the Internet:

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

GLBatch triangleBatch;

GLShaderManager shaderManager;

// the window size changes to accept the new width and height, where 0,0 represent the lower-left coordinates of the viewport in the window, w, h represent pixels
void ChangeSize(int w,int h) {
    
    glViewport(0.0, w, h);
}

// Make a one-time setup for the program
void SetupRC() {
    // Set the background color
    glClearColor(0.0f,1.0f,1.0f,0.0f);
    
    // Initialize the shader manager
    shaderManager.InitializeStockShaders();
    
    // Set the triangle, where the array vVert contains x,y, cartesian pairs of all 3 vertices.
    GLfloat vVerts[] = {
        0.5f,0.0f,0.0f,
        
        0.5f,0.0f,0.0f,

        0.0f,0.5f,0.0f,
    };
    // batch processing
    triangleBatch.Begin(GL_TRIANGLES,3);
    
    triangleBatch.CopyVertexData3f(vVerts);
    
    triangleBatch.End();
}

// Start rendering
void RenderScene(void) {
    // Clear a specific buffer or group of buffers
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
    
    // Set a set of floating-point numbers to represent purple
    GLfloat vRed[] = {1.0f,0.0f,1.0f,1.0f};
    
    // Passes to the storage shader, the GLT_SHADER_IDENTITY shader, which simply renders the geometry on the screen using the specified color and default Cartesian coordinates
    shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed);
    
    // Submit the shader
    triangleBatch.Draw();
    
    // Will render in the background buffer and then swap to the foreground at the end
    glutSwapBuffers();
}

int main(int argc,char* argv[]) {
    // Set the current working directory for MAC OS X
    gltSetWorkingDirectory(argv[0]);
    
    // Initialize the GLUT library
    glutInit(&argc, argv);
    
    /* Initialize the double buffering window with the GLUT_DOUBLE, GLUT_RGBA, GLUT_DEPTH, and GLUT_STENCIL symbols indicating the double buffering window, RGBA color mode, depth test, and template buffer */
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);
    
    //GLUT window size, title window
    glutInitWindowSize(800.600);
    
    glutCreateWindow("Triangle");
    
    // Register the callback function
    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));
        return 1;
    }
    
    / / call SetupRC
    SetupRC();
    glutMainLoop();
    return 0;
}
Copy the code

Running results:

Reprint please note the original source, shall not be used for commercial communication – any more