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

查看:34
本文介绍了从 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 个浮点数,这甚至不是一个完整的三角形.我只能假设这是一个顶点位置.你在这个循环的中间一直调用 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天全站免登陆