MAC 环境搭建Open GL


准备工作:

1.资源包下载:链接: https://pan.baidu.com/s/19jAhEYW0Mxkuj2vrKNpeyg 密码: bf5h

2.代码项目实例:https://github.com/Likoo7072/OpenGL.git

开始搭建

1.Xcode -> macOS -> APP


2.添加OpenGl.framework 和GLUT.framework系统库


2.0


3 .把下载解压好的CLTools.h,glew.h,libGLTools.a资源库拖入到项目中

A:libGLTools.a 直接拖到工程的Frameworks文件里面,另外删除 AppDelegate.h ,AppDelegate.m ,main.m ,ViewController.h  ViewController.m ; 创建 main.cpp
B:配置资源库的引入("$(SRCROOT)/OpenGlShare/include")

3.0

3.1
3.2
3.3
3.4


4.在main.cpp复制运行下面的代码

#include "GLTools.h"#include

GLBatch triangleBatch;

GLShaderManager shaderManager;

//0,0wh

void ChangeSize(int w,int h)

{

    glViewport(0,0, w, h);

}

//void SetupRC()

{

//glClearColor(0.0f,0.0f,1.0f,1.0f);

//shaderManager.InitializeStockShaders();//vVert3x,y,GLfloat vVerts[] = {

-0.5f,0.0f,0.0f,

0.5f,0.0f,0.0f,

0.0f,0.5f,0.0f,

};

//triangleBatch.Begin(GL_TRIANGLES,3);

triangleBatch.CopyVertexData3f(vVerts);

triangleBatch.End();

}

//void RenderScene(void)

{

//glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL

_BUFFER_BIT);

//

GLfloat vRed[] = {1.0f,0.0f,0.0f,1.0f};

//GLT_SHADER_IDENTITY

shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed);

//triangleBatch.Draw();//glutSwapBuffers();

}int main(int argc,char* argv[])

{

//MAC OS X

    gltSetWorkingDirectory(argv[0]);

//GLUT

    glutInit(&argc, argv);

/*GLUT_DOUBLEGLUT_RGBAGLUT_DEPTHGLUT_STENCIL

RGBA*/glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_

STENCIL);

//GLUTglutInitWindowSize(800,600);

<>“”

glutCreateWindow("Triangle");//glutReshapeFunc(ChangeSize);

glutDisplayFunc(RenderScene);//GLenum err = glewInit();if(GLEW_OK != err) {

        fprintf(stderr,"glew error:%s\n",glewGetErrorString(er

r));        return 1;

}

//SetupRCSetupRC();

glutMainLoop();

return 0;

}


5.效果图





你可能感兴趣的:(MAC 环境搭建Open GL)