Jump to content

  • Log In with Google      Sign In   
  • Create Account


obj doesn't draw


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
2 replies to this topic

#1 adrian_diesel   Members   -  Reputation: 134

Like
0Likes
Like

Posted 28 June 2013 - 04:38 PM

Hello

I'm using a obj loader in my ios app but it doesn't draw.

 

Here's the code i use to bind the buffers

cub.import("coloredcube.obj");
    
    
    for(int i=0;i<cub.getNumberOfVertices();i++)
        NSLog(@"%f %f %f",cub.getVertexBuffer()[i].position[1],cub.getVertexBuffer()[i].position[0],cub.getVertexBuffer()[i].position[2]);
        
    
    for(int i=0;i<=cub.getNumberOfIndices();i+=3)
        NSLog(@"%d %d %d",cub.getIndexBuffer()[i],cub.getIndexBuffer()[i+1],cub.getIndexBuffer()[i+2]);
    
    
    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(cub.getVertexBuffer()), cub.getVertexBuffer(), GL_STATIC_DRAW);
    
    glGenBuffers(1, &_indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cub.getIndexBuffer()), cub.getIndexBuffer(), GL_STATIC_DRAW);
    
    
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(ModelOBJ::Vertex), (const GLvoid *) offsetof(ModelOBJ::Vertex, position));

and to draw i use

 glBindVertexArrayOES(_vertexArray);  
 glDrawElements(GL_TRIANGLES, cub.getNumberOfIndices(), GL_UNSIGNED_INT, 0);

 

the the buffers returned by the ModelOBJ class are

 std::vector<Vertex> m_vertexBuffer;

 std::vector<GLuint> m_indexBuffer;

The loader seems to work as i output the vertexs in nslog

 

if i use some static coordinates binded to buffers it works

typedef struct {
    float Position[3];
    float Color[4];
} Vertex;

const Vertex Vertices[] = {
    {{1, -1, 0}, {1, 0, 0, 1}},
    {{1, 1, 0}, {0, 1, 0, 1}},
    {{-1, 1, 0}, {0, 0, 1, 1}},
    {{-1, -1, 0}, {0, 0, 0, 1}}
};

const GLubyte Indices[] = {
    0, 1, 2,
    2, 3, 0
};

What could be the problem?


Edited by adrian_diesel, 28 June 2013 - 04:39 PM.


Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 2130

Like
1Likes
Like

Posted 28 June 2013 - 09:02 PM

Probably because sizeof(cub.getVertexBuffer()) and sizeof(cub.getIndexBuffer()) don't do what you think they do. Since cub.getVertexBuffer() and cub.getIndexBuffer() return pointers, the sizeof() is giving you the size of a pointer, not the size of the buffer. You need to pass in the actual size of the buffers.



#3 adrian_diesel   Members   -  Reputation: 134

Like
0Likes
Like

Posted 28 June 2013 - 09:09 PM

Thank you , changed to

 glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, cub.getVertexSize()*cub.getNumberOfVertices(), &cub.getVertexBuffer()[0], GL_STATIC_DRAW);
    
    glGenBuffers(1, &_indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, cub.getIndexSize()*cub.getNumberOfIndices(), &cub.getIndexBuffer()[0], GL_STATIC_DRAW);
  

 

and it works






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