1.资源下载
Open GL 资源包
资源包里包含两个主要包含两个文件
2.开始配置
1.创建 Mac OS App
创建 Mac OS App2.添加GLUT.framework和 OpenGL.framework
选中项目文件 Build Phases -> Link Binary With Libraries
,添加 OpenGL.framework
、GLUT.framework
两个系统库
3.导入 OpenGL 资源包
将下载好的资源包解压,将 include
文件和 libGLTools.a
导入项目中,libGLTools.a
文件放入 Framework
中
4.重新初始化项目入口
-
1.删除项目中的
AppDelegate.h, AppDelegate.m, ViewController.h, ViewController.m, main.m
文件
-
2.创建
main.cpp
文件
取消创建头文件勾选
4.编译运行
将下方代码粘贴到 main.cpp
中,然后进行编译运行
#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,0.0,0.0,1.0f};
shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
void setupRC()
{
glClearColor(0.98f, 0.40f, 0.7f, 1);
shaderManager.InitializeStockShaders();
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();
}
int main(int argc,char *argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);
glutInitWindowSize(800, 600);
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;
}
运行结果
运行成功3.配置中可能会遇到的问题
-
1.头文件引用错误
将
#include <fileName.h>
改为#include "fileName.h"
-
2.
libGLTool.a
not found
网友评论