Jump to content
  • Advertisement
Sign in to follow this  
polyfrag

Android orthographic interference glDrawArrays/glVertexAttribPointer

This topic is 2027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This orthrographic image draws fine:

  glDisable(GL_DEPTH_TEST); 
    glUseProgram(g_program[ORTHO]); 
    glUniform1f(g_slots[ORTHO][WIDTH], (float)g_width); 
    glUniform1f(g_slots[ORTHO][HEIGHT], (float)g_height); 
    glUniform4f(g_slots[ORTHO][COLOR], 1, 1, 1, 1); 
    glEnableVertexAttribArray(g_slots[ORTHO][POSITION]); 
    glEnableVertexAttribArray(g_slots[ORTHO][TEXCOORD]); 
    glBindBuffer(GL_ARRAY_BUFFER, 0); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 
... 
  glVertexAttribPointer(g_slots[ORTHO][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
    glVertexAttribPointer(g_slots[ORTHO][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
    glDrawArrays(GL_TRIANGLES, 0, 6); 
... 
    glEnable(GL_DEPTH_TEST);

 

But if I place this before it, it doesn't draw:

    glUseProgram(g_program[MODEL]); 
        ... 
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[frame]); 
    glVertexAttribPointer(g_slots[MODEL][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(CVertexArray2), (void*)offsetof(CVertexArray2,texcoord));

        glUseProgram(g_program[BILLBOARD]); 
        ... 
        glVertexAttribPointer(g_slots[BILLBOARD][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
        glVertexAttribPointer(g_slots[BILLBOARD][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
        glDrawArrays(GL_TRIANGLES, 0, 6);

 

If I get rid of the last glDrawArrays it draws, or if I remove glVertexAttribPointer(g_slots[MODEL][TEXCOORD]...

Any ideas why?

 

Share this post


Link to post
Share on other sites
Advertisement

Here's what I broke the problem down to.

 

The ortho quad will draw if I comment any of these lines:

 

        glUseProgram(g_program[BILLBOARD]); 
        glEnableVertexAttribArray(g_slots[BILLBOARD][POSITION]); 
        glEnableVertexAttribArray(g_slots[BILLBOARD][TEXCOORD]); 
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glVertexAttribPointer(g_slots[BILLBOARD][POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[0]); 
        glVertexAttribPointer(g_slots[BILLBOARD][TEXCOORD], 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, &vertices[3]); 
        
        glDrawArrays(GL_TRIANGLES, 0, 6);

 

It has something to do with the texture because if I get rid of the texture in the billboard shaders, the ortho quad draws:

 

// billboard.frag

varying lowp vec2 TexCoordOut; 
uniform sampler2D Texture;

void main(void) 
{ 
  lowp vec2 TexCoord = vec2(0,0); 
    gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0) * texture2D(Texture, TexCoord); 
    //gl_FragColor = vec4(1,1,1,1); 
}

 

Vertex shader billboard.vert somehow effects the vertices of the ortho shader. The ortho quad only draws in the right part of the screen if I remove the line

 

    TexCoordOut = TexCoordIn;

attribute vec4 Position;
attribute vec2 TexCoordIn; 
varying vec2 TexCoordOut;

void main(void) 
{ 
    gl_Position = Position; 
    TexCoordOut = TexCoordIn; 
}

Share this post


Link to post
Share on other sites

Fixed the problem by packing everything into VBO's. Inconvenient, especially for text, but it solved the problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!