OpenGL ES 1.1到2.0有重大变化吗?
我正在使用 cocos2d 创建一个 iPhone 应用程序,并尝试使用以下 OpenGL ES 1.1 代码。但是,我不擅长 OpenGL,并且我的应用程序使用 OpenGL ES 2.0,因此我需要对其进行转换。
因此我想知道,将以下代码从 ES 1.1 转换为 ES 2.0 有多困难?有没有一些来源可以告诉我哪些方法需要替换等?
-(void) draw
{
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glColor4ub(_color.r, _color.g, _color.b, _opacity);
glLineWidth(1.0f);
glEnable(GL_LINE_SMOOTH);
if (_opacity != 255)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//non-GL code here
if (_opacity != 255)
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
I'm creating an iPhone app with cocos2d and I'm trying to make use of the following OpenGL ES 1.1 code. However, I'm not good with OpenGL and my app makes use of OpenGL ES 2.0 so I need to convert it.
Thus I was wondering, how difficult would it be to convert the following code from ES 1.1 to ES 2.0? Is there some source that could tell me which methods need replacing etc?
-(void) draw
{
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
glColor4ub(_color.r, _color.g, _color.b, _opacity);
glLineWidth(1.0f);
glEnable(GL_LINE_SMOOTH);
if (_opacity != 255)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//non-GL code here
if (_opacity != 255)
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不太熟悉 OpenGL,那么事情就不会那么容易了。
OpenGL ES 2.0 不再有固定功能的管道。这意味着您必须使用 GLSL 顶点和片段着色器自行管理顶点转换、光照、纹理等。您还必须自己跟踪变换矩阵,不再有
glMatrixMode
、glPushMatrix
、glTranslate
等。也不再有内置顶点属性(例如
glVertex
、glColor
等)。因此,这些函数以及相应的数组函数(例如glVertexPointer
、glColorPointer
...)和gl(En/Dis)ableClientState
,也已被删除。相反,您需要通用顶点属性函数(glVertexAttrib
、glVertexAttribPointer
和gl(En/Dis)ableVertexAttribArray
,其行为类似)以及相应的顶点着色器赋予这些属性正确的含义。我建议您查看一本好的 OpenGL ES 2.0 教程或书籍,因为从 1.1 移植到 2.0 确实是一个重大变化,至少如果您从未听说过有关着色器的任何内容。
It will not be that easy if you're not so fit in OpenGL.
OpenGL ES 2.0 doesn't have a fixed-function pipeline anymore. This means you have to manage vertex transformations, lighting, texturing and the like all yourself using GLSL vertex and fragment shaders. You also have to keep track of the transformation matrices yourself, there are no
glMatrixMode
,glPushMatrix
,glTranslate
, ... anymore.There are also no buitlin vertex attributes anymore (like
glVertex
,glColor
, ...). So these functions, along with the corresponding array functions (likeglVertexPointer
,glColorPointer
, ...) andgl(En/Dis)ableClientState
, have been reomved, too. Instead you need the generic vertex attribute functions (glVertexAttrib
,glVertexAttribPointer
andgl(En/Dis)ableVertexAttribArray
, which behave similarly) together with a corresponding vertex shader to give these attributes their correct meaning.I suggest you look into a good OpenGL ES 2.0 tutorial or book, as porting from 1.1 to 2.0 is really a major change, at least if you never have heard anything about shaders.