OpenGL ES 1.1到2.0主要变化?

问题描述:

我正在使用cocos2d创建一个iPhone应用程序,我试图使用以下OpenGL ES 1.1代码。但是,我不喜欢OpenGL,我的应用程序使用OpenGL ES 2.0,所以我需要转换它。

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.

因此我想知道,将以下代码从ES 1.1转换为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?

-(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);
}


如果你不适合OpenGL。

It will not be that easy if you're not so fit in OpenGL.

OpenGL ES 2.0不再有固定功能的管道了。这意味着你必须使用GLSL顶点和片段着色器来管理顶点变换,光照,纹理等。你还必须自己跟踪转换矩阵,没有 glMatrixMode glPushMatrix glTranslate ,...。

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.

也不会有buitlin顶点属性(如 glVertex glColor ,...)。所以这些函数,以及相应的数组函数(如 glVertexPointer glColorPointer ,...)和 gl(En / Dis)ableClientState ,也被拒绝。相反,你需要通用的顶点属性函数( glVertexAttrib glVertexAttribPointer gl )ableVertexAttribArray ,它们的行为类似)以及一个对应的顶点着色器,以赋予这些属性正确的含义。

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.

我建议你看看好OpenGL ES 2.0教程或书籍,从1.1移植到2.0真的是一个重大的变化,至少如果你从来没有听说过任何关于着色器。

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.