---
title: "cocos2d 1.x升级到2.x遇到error"
author: "mmdev"
date: "2012-12-15T22:22:00Z"
tags: []
slug: "cocos2d-1-x-2-x-error"
draft: false
lastmod: "2013-01-05T09:48:33Z"
id: 1761002
url: "https://mmdev.iteye.com/blog/1761002"
---

============================================================

博文原创，转载请声明出处

[蓝岩--移动互联网老兵](http://blog.csdn.net/shencaifeixia1)

============================================================

近日需要将一工程由cocos2d 1.x升级到2.x，结果遇到以下error

```
Use of undeclared identifier 'GL_COLOR_ARRAY'
Use of undeclared identifier 'GL_TEXTURE_COORD_ARRAY'
```

先说解决方案：

1、在opengl渲染之前，注释以下代码（或类似功能代码）

```
//glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//glDisableClientState(GL_COLOR_ARRAY);
//glDisable(GL_TEXTURE_2D);
//glVertexPointer(2, GL_FLOAT, 0, circleVertices_);
//glColor4f(color_.r/255.0f, color_.g/255.0f, color_.b/255.0f, opacity_/255.0f);
```

2、在gl渲染之后，，注释以下代码（或类似功能代码）

```
// restore default GL state
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glEnableClientState(GL_COLOR_ARRAY);
//glEnable(GL_TEXTURE_2D);
```

3、在gl渲染之初，加上下面代码

```
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color );
```

----------原因：

cocos2d 从1.x升级到2.x，变化较大，奉劝一句“新版未必好，升级需谨慎”，最好在升级之前先浏览一下官方的升级指导：[http://www.cocos2d-iphone.org/wiki/doku.php/prog\_guide:migrate\_to\_v2.0](http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:migrate_to_v2.0)

祝大伙升级顺利，如遇问题，google之，同时也欢迎留言交流。