从OpenGL 1.1移植到OpenGL-ES 2.0时出现的问题 [英] Issue when porting from OpenGL 1.1 to OpenGL-ES 2.0

查看:86
本文介绍了从OpenGL 1.1移植到OpenGL-ES 2.0时出现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的opengl-es 2.0代码:

this is my opengl-es 2.0 code :

{
    for (surfnum=0;surfnum<surftotal;surfnum++){
        for (i=0;i<triNum[surfnum];i++){
            GLfloat *Vertices[] = { triArray[surfnum][i].normpt1,  triArray[surfnum][i].normpt2,triArray[surfnum][i].normpt3};
            glGenBuffers(1, &ui32Vbo);
            glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
            unsigned int uiSize = 3 * (sizeof(GLfloat) * 1); 
            glBufferData(GL_ARRAY_BUFFER, uiSize,*Vertices, GL_STATIC_DRAW);
        }
    }
}
for(int i = 0; i < 80000; ++i)
{
    glClear(GL_COLOR_BUFFER_BIT);
    int i32Location = glGetUniformLocation(uiProgramObject, "projmatrix");
    glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity);
    glEnableVertexAttribArray(VERTEX_ARRAY);
    glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0,i);
    eglSwapBuffers(eglDisplay, eglSurface);
}

这是我的opengl-es 2.0代码.我正在研究opengl 1.1,在其中我可以显示iso表面形式的数据.

This is my opengl-es 2.0 code . I was working on opengl 1.1 in which i was able to show the iso surface form data .

这是我的Opengl 1.1代码:

This is my Opengl 1.1 code:

void drawTriangle()
{
    int surfnum, i;
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0,0.6,0.1);


    for (surfnum=0;surfnum<surftotal;surfnum++)
    {
        for (i=0;i<triNum[surfnum];i++)
                {
            glBegin(GL_POLYGON);
            glNormal3fv(triArray[surfnum][i].normpt1);
            glVertex3fv(triArray[surfnum][i].pt1);
            glNormal3fv(triArray[surfnum][i].normpt2);
            glVertex3fv(triArray[surfnum][i].pt2);
            glNormal3fv(triArray[surfnum][i].normpt3);
            glVertex3fv(triArray[surfnum][i].pt3);
            glEnd();
            glFlush();
            glutSwapBuffers();
        }
    }
}

我没有得到与opengl相同的结果,在opengl-es 2.0中也是

I am not getting the same result as I was getting in opengl , in opengl-es 2.0 also a

警告如下:libegl:使用软件后备;
输出发生非常缓慢
这里的输出超出窗口

warning coming like: libegl: use software fallback ;
output occurs very slowly
here the output goes out of window

如果您需要其他信息,请问我.

If you want an other information ask me.

推荐答案

您的代码没有意义.

{
    for (surfnum=0;surfnum<surftotal;surfnum++){
        for (i=0;i<triNum[surfnum];i++){
            GLfloat *Vertices[] = { triArray[surfnum][i].normpt1,  triArray[surfnum][i].normpt2,triArray[surfnum][i].normpt3};
            glGenBuffers(1, &ui32Vbo);
            glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
            unsigned int uiSize = 3 * (sizeof(GLfloat) * 1); 
        glBufferData(GL_ARRAY_BUFFER, uiSize,*Vertices, GL_STATIC_DRAW);
        }
    }
}

您是否真的为每个三角形创建了一个缓冲区对象?嗯,您甚至都没有这样做,因为每组3个浮点数只有一个缓冲区对象,它甚至不是完整的 triangle .我只能假定这是一个顶点位置.您在此循环的中间一直调用glGenBuffers,因此它将忠实地生成另一个缓冲区对象.创建太多的缓冲区对象可能就是为什么您遇到软件后备的原因.

Are you actually creating a buffer object for each triangle? Well, you're not even doing that, because you only have a buffer object for each set of 3 floats, which isn't even a full triangle. I can only assume that this is a vertex position. You keep calling glGenBuffers in the middle of this loop, so it will dutifully generate another buffer object. Creating too many buffer objects may be why you're hitting software fallbacks.

此外,normpt1是否不包含正常位置而不是位置?

Also, doesn't normpt1 contain the normal, not the position?

然后是这个:

for(int i = 0; i < 80000; ++i)
{
    glClear(GL_COLOR_BUFFER_BIT);
    int i32Location = glGetUniformLocation(uiProgramObject, "projmatrix");
    glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity);
    glEnableVertexAttribArray(VERTEX_ARRAY);
    glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0,i);
    eglSwapBuffers(eglDisplay, eglSurface);
}

首先,您没有使用glBindBuffer缓冲对象.是的,我知道它仍然是从前的约束,但是明确说明这些事情始终是一件好事.

First, you didn't glBindBuffer your buffer object. Yes, I know it is still bound from before, but it's always good to be explicit about these things.

最重要的是,这是什么:glDrawArrays(GL_TRIANGLES, 0,i);? i不是数组索引吗?第三个参数必须是要绘制的顶点数.除非此值可被3整除,否则GL_TRIANGLES将失败.

Most importantly, what is this: glDrawArrays(GL_TRIANGLES, 0,i);? Isn't i the array index? The third parameter needs to be the number of vertices to draw. And GL_TRIANGLES will fail unless this value is divisible by 3.

但这没关系,因为您上次创建的缓冲对象仅具有足够的空间容纳1个顶点.因此,不可能进行渲染.

But that doesn't matter, since the buffer object you last created only has enough room for 1 vertex. So it is impossible to render from.

这篇关于从OpenGL 1.1移植到OpenGL-ES 2.0时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆