• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jsmtux

invalid operation error on glBindVertexArray

6 posts in this topic

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

0

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.

1

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

0

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 ___
0

Share this post


Link to post
Share on other sites

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.

0

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

Share this post


Link to post
Share on other sites

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  
Followers 0