xcode OpenGL ES 1.1 到 2.0 的重大变化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7777605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenGL ES 1.1 to 2.0 a major change?
提问by FBryant87
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.
我正在使用 cocos2d 创建一个 iPhone 应用程序,并且我正在尝试使用以下 OpenGL ES 1.1 代码。但是,我不擅长 OpenGL,我的应用程序使用 OpenGL ES 2.0,所以我需要转换它。
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?
因此我想知道,将以下代码从 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);
}
回答by Christian Rau
It will not be that easy if you're not so fit in OpenGL.
如果您不太适合 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.
OpenGL ES 2.0 不再具有固定功能的管道。这意味着您必须使用 GLSL 顶点和片段着色器自行管理顶点变换、照明、纹理等。您还必须自己跟踪变换矩阵,不再有glMatrixMode
, glPushMatrix
, glTranslate
, ... 了。
There are also no buitlin vertex attributes anymore (like glVertex
, glColor
, ...). So these functions, along with the corresponding array functions (like glVertexPointer
, glColorPointer
, ...) and gl(En/Dis)ableClientState
, have been reomved, too. Instead you need the generic vertex attribute functions (glVertexAttrib
, glVertexAttribPointer
and gl(En/Dis)ableVertexAttribArray
, which behave similarly) together with a corresponding vertex shader to give these attributes their correct meaning.
也不再有 buitlin 顶点属性(如glVertex
, glColor
, ...)。因此,这些函数以及相应的数组函数(如glVertexPointer
, glColorPointer
, ...)和gl(En/Dis)ableClientState
也已被删除。相反,您需要通用顶点属性函数(glVertexAttrib
,glVertexAttribPointer
和gl(En/Dis)ableVertexAttribArray
,其行为类似)以及相应的顶点着色器来赋予这些属性正确的含义。
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.
我建议您查看一个好的 OpenGL ES 2.0 教程或书籍,因为从 1.1 移植到 2.0 确实是一个重大变化,至少如果您从未听说过着色器。