一、准备资料
资料.png二、配置 openGL 环境
- 打开Xcode -> macOS -> Cocoa App 1.png
- AppDelegate.h、AppDelegate.m、main.m、ViewController.h、 ViewController.m ; 2.png
-
创建 main.cpp文件
3.png
4.png - 添加OpenGl.framework 和 GLUT.framework 两个系统库 5.png
- 添加资料 6.png
三、测试环境是否搭建成功
在main.cpp中复制一下代码:
//
// main.cpp
// OpenGLTest0
//
// Created by 邓亚洲 on 2019/4/24.
// Copyright © 2019年 dengyazhou. All rights reserved.
//
#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;
}
四、重点
#include<文件名.h> 修改为 #include"文件名"
编译,将文件“< >”系统引入,改为" "普通引入
网友评论