jsmtux

Member
  • Content count

    5
  • Joined

  • Last visited

Community Reputation

235 Neutral

About jsmtux

  • Rank
    Newbie
  1. 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);
  2. 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
  3. 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
  4. Going on with the problem, if I change my function to this: lua_rawgeti(L, LUA_REGISTRYINDEX, tmp.luaRef); luaL_checktype(L, -1, LUA_TTABLE); return 1; Checktype says that a lua table is on top of the stack, but if I print this return value from lua it says it is a nil value
  5. Hi all, I've been trying to integrate lua into my game but I've been having some difficulties, I hope you can help me because I'm stuck. In my code I create metatables in Lua and store them in c with lua_getglobal(L,newTable); lua_call(L,0,1);//lua creates a new metatable and returns it int luaRef = luaL_ref(L,LUA_REGISTRYINDEX); newTable is a function that creates a new metatable and returns it, then I call it and get the reference from the stack and store it in luaRef Once I have this reference, if I need to call a function  of this metatable from c I do: lua_getglobal(L,name.c_str());//Get the table name lua_getfield(L,-1,"function");//set the function from the table lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);//set the table object lua_call(L,1,0);//call the function And it works. My problem is that when I try to push this reference back to lua so that I can call these functions I get a My code is int Scripted::LgetObject(lua_State *L){     lua_getglobal(L,name.c_str());     lua_rawgeti(L, LUA_REGISTRYINDEX, tmp.luaRef);     return 1; } and from Lua: object=getObject() object:function() As I understand, the avobe C code pushes de table into the stack, but all lua receibes is a nil value. I've been trying to solve this for days and I don't know what to do next, please point me in the right direction Thanks