Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


invalid operation error on glBindVertexArray


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 jsmtux   Members   -  Reputation: 235

Like
0Likes
Like

Posted 21 July 2013 - 08:37 AM

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



Sponsor:

#2 WiredCat   Members   -  Reputation: 365

Like
1Likes
Like

Posted 21 July 2013 - 01:39 PM

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.



#3 jsmtux   Members   -  Reputation: 235

Like
0Likes
Like

Posted 22 July 2013 - 11:57 AM

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



#4 WiredCat   Members   -  Reputation: 365

Like
0Likes
Like

Posted 22 July 2013 - 01:59 PM

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 ___, 22 July 2013 - 01:59 PM.


#5 Sponji   Members   -  Reputation: 1360

Like
0Likes
Like

Posted 22 July 2013 - 03:55 PM

Are you unbinding the VAO before calling SFML's stuff? Would also help a lot if you could make a minimal example to show the problem.


Derp

#6 jsmtux   Members   -  Reputation: 235

Like
0Likes
Like

Posted 23 July 2013 - 10:11 AM

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


#7 Sponji   Members   -  Reputation: 1360

Like
0Likes
Like

Posted 23 July 2013 - 11:55 AM

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

Derp




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS