Configuring the OpenGL Programming environment on MAC OS X Yosemite 10.10.5

Source: Internet
Author: User



This tutorial mainly refers to the video on YouTube Getting Started in OpenGL with Glfw/glew in Xcode 6, this video is a bit of a problem and cannot be copied. I through my Own (blind) (the cat) (Touch) (The Dead) (the) side (son) comments, now give a possible installation of a successful program, as to whether success, see the good fortune of you.



First of all, your Mac needs to have the latest Xcode,command line tool, these are the most basic, it is estimated that you have the conditions. Next, download installs CMake (https://cmake.org/), this also does not have the difficulty, and installs the ordinary software no difference.



Next, we formally start configuring our OpenGL Programming Environment:



1. Download Glew (http://glew.sourceforge.net/), point the middle of the red zip.








2. Download GLFW (https://cmake.org/) and click on the first orange box on the right (Download GLFW 3.1.2).








3. Open Create A new Xcode project--Command line Tool



Then give the project a name (for example: BASEOPENGL), choose to save the path to the desktop (more convenient). Then, unzip and move the GLFW and Glew downloaded in the previous two steps to the project folder, and delete the version number for convenience.



4. Create a folder named Build under the GLFW folder, there is a CMakeLists.txt under the GLFW folder, so we need to compile this library with CMake software. Open the CMake, drag the CMakeLists.txt to the top of the CMake window, and you can see that its path is automatically entered into two forms, one of: where is the source code: the other is where to build the BI Naries. Under the latter path, add a/build to create the binaries in the build folder that we just created.



5. Under the CMake window, under Configure, there is a drop-down form in the pop-up menu, select Xcode in the dropdown form, under the form or its default "Use default native compilers", then click Done.



6. The 5th Step after the CMake window appeared a lot of background is red characters, in the first option: Build_shared_libs after the hook, point Configure, found that the red background disappeared, and then point Generate. Then we can find a lot of new files in the build folder we created earlier:













7. Double-click into the Glfw.xcodeproj file in the build folder. Then notice the button next to the Run button in the upper-left corner of the window: All_build, change it to install, and check My Mac. Then click the Black Triangle Run button to compile this file. After compiling, there will be a lot of warnings, do not care, this is expected. After this step, the GLFW Dynamic link library and header files exist in some folders of your computer.     8. The compilation process for installing Glew,glew below differs from GLFW. First open the command line, then switch the path to the inside of the Glew folder, then enter the sudo make install and enter the computer password. Then the computer began to compile the Glew, it takes about 10 minutes to compile, please wait patiently. When you are finished, you can see the Include folder and the Lib folder under the Glew folder, and store the header and library files for this package, respectively.  9. Next we modify the Xcode configuration environment. First open the previously created Baseopengl project, then select the first Baseopengl on the left-hand side of the list, point to build phases on the right, then click Link Binary with Libraries, dot + sign, search Opengl.framework, add.   10. Then click on the + sign to open the window just now, this time choose Add Other. Then press shift+command+g and enter \usr\local to jump to this path. Go to the Lib folder under the path and select Libglew.1.13.0.dylib. Repeat the previous steps, then go to this folder and select Libglfw.3.1.dylib. It is possible that you can not find these two libraries under this path (I did not find it in the beginning), then try to find in the \usr\lib folder, find and Glew and GLFW related library files are copied and pasted into the \usr\local\lib, the original ones deleted.  11. The 10th step adds a opengl.framework and two library files, this step will switch the tab from build phases to build Settings, find the Search Paths column, in the header search Paths midpoint + number, enter /usr/local/include, added in Library Search Paths:/usr/local/lib. It is possible that the Glew or GLFW header file does not appear in the/usr/local/include case, please go to/usr/include, find the relevant folder (GL, GLFW) after the copy paste into the/usr/local/include, Then delete the original file.  12. Find the other Linker Flags in the Linking column and add the-lglew link parameter. At this point, the basic environment is configured, the next step is to write code to test. The test code is as follows:
#include <iostream> #include <GL/glew.h> #include <GLFW/glfw3.h> void Render(void)
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    {
        glColor3f(1.0,0.0,0.0);
        glVertex2f(0, .5);
        glColor3f(0.0,1.0,0.0);
        glVertex2f(-.5,-.5);
        glColor3f(0.0, 0.0, 1.0);
        glVertex2f(.5, -.5);
    }
    glEnd();
} int main(int argc, const char * argv[]) {
    GLFWwindow* win; if(!glfwInit()){ return -1;
    }
    win = glfwCreateWindow(640, 480, "OpenGL Base Project", NULL, NULL); if(!win)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    } if(!glewInit())
    { return -1;
    }
    glfwMakeContextCurrent(win); while(!glfwWindowShouldClose(win)){
        Render();
        glfwSwapBuffers(win);
        glfwPollEvents();
    }
    glfwTerminate();
    exit(EXIT_SUCCESS); return 0;
}


The test result is such a picture:






Configuring the OpenGL Programming environment on MAC OS X Yosemite 10.10.5


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.