开发者

Issue when porting from OpenGL 1.1 to 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,开发者_C百科 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);
}

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 .

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

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

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.


Your code doesn't make sense.

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

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.

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

And then there's this:

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

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.

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜