Sign in to follow this  

invalid operation error on glBindVertexArray

This topic is 1606 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

Hi, I've been having a weird problem for a long time and I hope you can help me.

 

I'm trying to use VAOs in my engine, I load them and I get no errors, but when I call glBindVertexArray I get error 1282. The weird thing is that in the first iteration of the game loop I don't get that error. So there must be some operation that invalidates the VAO.

 

The only way I can show things in screen is by calling glEnableVertexAttribArray, glVertexAttribIPointer, glEnableVertexAttribArray, glVertexAttribPointer for every bufferbefore painting as if I hadn't set up the VAO.

 

Do you have any idea of what is wrong?

Thanks

Share this post


Link to post
Share on other sites

your graphics card may not support these extensions try on a different computer, or you dont have that functions described properly

in c++ is something like this:

 

header 

PFNGLTEXIMAGE3DPROC glTexImage3D;

source

 

glTexImage3D            = (PFNGLTEXIMAGE3DPROC)    wglGetProcAddress("glTexImage3D");

 

i dont know but i could be in glew.h

 

 

BUT

 

 

your problem seems to be simple but quite hard to solve look for your code for bad drawing calls

maybe you dont disable some statements on frame end.

Really try with blank project and try to do that you want to make, then compare it to your code.

Share this post


Link to post
Share on other sites

Thank you very much for your answer.

I found out that the vertex array gets invalidated when I call the SFML display function.

But I still have no clue about how to fix it or what kind of calls could lead to this behaviour

Share this post


Link to post
Share on other sites

can you show your drawing code?

maybe you dont have properly closed last face? (2 or 1 vertex instead of 3)

VAO? i use VAO too but i dont have something like glgenbuffers etc

i have just simple array that is drawn like:

 

 

void __fastcall TachoGLModel::DrawModelVBO(t3dpoint punkt)
{
if (ModelCanBeUsed == false) return;

glVertexPointer(3, GL_FLOAT, sizeof(t3dpoint), &VBO_V[0]);
glNormalPointer(GL_FLOAT, sizeof(t3dpoint),&VBO_N[0]);
glTexCoordPointer(2, GL_FLOAT, sizeof(textpoint),&VBO_T[0]);
if (USE_COLOR_MAP == true) {

glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, &VBO_C[0]);

}

int i,j;


if (Textures.Length == 0) {
for (i = 0; i < Matrixarr.Length; i++)
glDrawArrays(matrixtogl(Matrixarr[i]), VBO_BE[i].INDEX_START , VBO_BE[i].length);
// FCyfra->ProjectTextures

if (USE_COLOR_MAP == true) glDisableClientState(GL_COLOR_ARRAY);
return;
}
//if( Textures.Length == 0) ShowMessage("NO");

for (i = 0; i < Matrixarr.Length; i++) {
//if (classifyapointagainstaplane(punkt,VBO_N[VBO_BE[i].INDEX_START],FACE_DISTANCE[i]) == isFront) {
if (EditMode == false)
if (Textures[Textureindex[i]].ID != 2)
if (Textures[Textureindex[i]].ID != 1) {
//


if ( Textures.Length > 0 )
glBindTexture(GL_TEXTURE_2D, Textures[ Textureindex[i] ].pointer);

glDrawArrays(matrixtogl(Matrixarr[i]), VBO_BE[i].INDEX_START , VBO_BE[i].length);


}


if (EditMode == true) glDrawArrays(matrixtogl(Matrixarr[i]), VBO_BE[i].INDEX_START , VBO_BE[i].length);
}


glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
if (EditMode == true)
for (i = 0; i < Matrixarr.Length; i++)
if (Textures[Textureindex[i]].ID == 1) {
if(Textures.Length > 0)
glBindTexture(GL_TEXTURE_2D,Textures[Textureindex[i]].pointer);
glDrawArrays(matrixtogl(Matrixarr[i]), VBO_BE[i].INDEX_START , VBO_BE[i].length);




}
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);


if (USE_COLOR_MAP == true) glDisableClientState(GL_COLOR_ARRAY);

}


 

 

 

 

 

 

 

 

 

 

 

 

show your vertex array and drawing routine with initialization of the VAO too

Edited by ___

Share this post


Link to post
Share on other sites

Hi all, thanks for your time.

The code I use to initialize the vaos is:

glGenVertexArrays(1, &iVAO);
glBindVertexArray(iVAO);

glGenBuffers(5, m_Buffers);

//here I load the buffers' information and the images

glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0],
               GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0],
                GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0],
                GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Bones[0]) * Bones.size(), &Bones[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size()*3, &Indices[0],
                GL_STATIC_DRAW);
    
glBindVertexArray(0);

And the code to draw them is:

glBindVertexArray(iVAO);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
glEnableVertexAttribArray(BONE_ID_LOCATION);
glVertexAttribIPointer(BONE_ID_LOCATION, 4, GL_INT, sizeof(VertexBoneData), (const GLvoid*)0);
glEnableVertexAttribArray(BONE_WEIGHT_LOCATION);
glVertexAttribPointer(BONE_WEIGHT_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);

for (unsigned int i = 0 ; i < meshes.size() ; i++) {
    const unsigned int MaterialIndex = meshes[i].MaterialIndex;

   if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
       dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
   }
       
    glDrawElementsBaseVertex(GL_TRIANGLES,
                              meshes[i].NumIndices,
                              GL_UNSIGNED_INT,
                              (void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
                              meshes[i].BaseVertex);
}

// Make sure the VAO is not changed from the outside
glBindVertexArray(0);

And this way it works, but if the VAO weren't invalid It should work like this

glBindVertexArray(iVAO);
    
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Buffers[INDEX_BUFFER]);

for (unsigned int i = 0 ; i < meshes.size() ; i++) {
    const unsigned int MaterialIndex = meshes[i].MaterialIndex;

   if (MaterialIndex < maps.size() && maps[MaterialIndex]) {
       dynamic_cast<Image*>(maps[MaterialIndex])->Bind();
   }
       
    glDrawElementsBaseVertex(GL_TRIANGLES,
                              meshes[i].NumIndices,
                              GL_UNSIGNED_INT,
                              (void*)(sizeof(unsigned int) * meshes[i].BaseIndex),
                              meshes[i].BaseVertex);
}

// Make sure the VAO is not changed from the outside
glBindVertexArray(0);

Share this post


Link to post
Share on other sites

This works at least for me.

// g++ sfml_vao.cpp -lsfml-graphics -lsfml-window -lsfml-system -lGL -lGLEW 

#include <SFML/Graphics.hpp>
#include <GL/glew.h>
#include <cstdio>

unsigned int vbo, ibo, vao;

const char *vs = "#version 150\n in vec3 vs_Position; void main() { gl_Position = vec4(vs_Position, 1); }";
const char *fs = "#version 150\n out vec4 o; void main() { o = vec4(1,0,0,1); }";

void init() {
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    glGenBuffers(1, &vbo);
    glGenBuffers(1, &ibo);

    float vertices[] = {
        -0.5f, -0.5f, 0.1f,
         0.5f, -0.5f, 0.1f,
         0.5f,  0.5f, 0.1f,
        -0.5f,  0.5f, 0.1f,
    };

    unsigned int indices[] = {
        0, 1, 2,
        0, 2, 3
    };

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

void draw() {
    glBindVertexArray(vao);
    glDrawElementsBaseVertex(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, 0);
    glBindVertexArray(0);
}

void check() {
    GLenum err = glGetError();
    if(err) {
        printf("fuu! %d\n", err);
    }
}

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    glewInit();

    sf::Shader shader;
    shader.loadFromMemory(vs, fs);

    init();

    while(window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
                return 0;
            }
        }

        window.clear();

        sf::Shader::bind(0);
        window.draw(shape);
        check();

        sf::Shader::bind(&shader);
        draw();
        check();

        window.display();
    }

    return 0;
}

Share this post


Link to post
Share on other sites

This topic is 1606 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this