CCGLViewImpl-desktop.cpp
//在glfwCreateWindow前插入下面4行
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
...
glfwCreateWindow();
CCClippingNode.cpp
//glGetIntegerv(GL_STENCIL_BITS, &g_sStencilBits);
//改为
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &g_sStencilBits);
CCConfiguration.cpp
//glGetString(GL_EXTENSIONS);
//改为
glGetStringi(GL_EXTENSIONS,i);
CCGL-mac.h
//#import
//改为
#import <OpenGL/gl3.h>
CCClippingNode.cpp
添加vao支持,opengl3的draw必须绑定vao,否则会报GL_INVALID_OPERATION错误
Vec2 vertices[] = {
Vec2(-1, -1),
Vec2(1, -1),
Vec2(1, 1),
Vec2(-1, 1)
};
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
同理,UILayout.cpp,CCLayer.cpp 也需要添加vao支持
另外,shader需要支持glsl 330
CCGLProgram.cpp
const GLchar *sources[] = {
"#version 330\n",
(type == GL_FRAGMENT_SHADER ? "out vec4 FragColor;\n" : "\n"),
顶点着色器中 attribute 改为 in; varying 改为 out
in vec4 a_position;
in vec4 a_color;
in vec2 a_texCoord;
out vec4 v_fragmentColor;
out vec3 v_texCoord;
void main()
{
gl_Position = CC_PMatrix * vec4(a_position.xy,0,a_position.w);
v_fragmentColor = a_color;
v_texCoord = vec3(a_texCoord,a_position.z);
}
片元着色器中varying改为in;
texture2D改为texture;
gl_FragColor改为自定义的FragColor
in vec4 v_fragmentColor;
in vec2 v_texCoord;
void main()
{
FragColor = v_fragmentColor * texture(CC_Texture0, v_texCoord);
}