First, excuse me for the mistakes I make but I'm french and don't use english often enough.
I've already used OpenGL 1.2 a few times, but now I want to learn the last version of OpenGL.
So I've wrote a program which load OBJ file, create a VBO and display it with shaders. At first, I only consider vertices and gave a unique color for every vertex. But the screen keeps being black so I've simplify my program but I still don't have any results. I don't find where is my mistake so if you could help me that would be great.
Here's an extract of the code where I think the error is. For now, there is no camera.
Thanks in advance for the precious help you can give me.
the creation of the VBO
GLuint Renderer::makeBuffer(GLenum target, const void *buffer_data)
{
GLsizei buffer_size = sizeof(buffer_data);
GLuint buffer; glGenBuffers(1, &buffer);
glBindBuffer(target, buffer);
glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW);
return buffer;
}
Try using a z coord of 0 instead of -1, that's right on the clipping plane and may end up being clipped.
Also your coordinates have clockwise winding, typically opengl uses counterclockwise for front facing, though this only matters if you have backface culling enabled.
sizeof() a pointer only returns the size of the pointer (4 bytes), not the size of the array, so you'll need to explicitly pass the length of the array to your makebuffer function. Right now your buffers are only 4 bytes long.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Thank you so much karwosts for you help, now it works !
Indeed I was only creating VBO of 8 bytes (I have a 64 bit computer, that's why it's 8 and not 4 I guess). I would have taken days to find this mistake, so really thanks a lot !!!!!
I'm back again because I've been trying for more than two hours now to display objects loading from obj files and I have again the same black screen.
I've created a obj file with the same square I was giving the vertices in the array vertex_data but I can't make it work... I've check the data that are loaded from the obj file, they are the same as the ones in arrays.
The only difference is that I'm using now a array of glm::vec4 instead of an array of float. Here's the code :
I've changed the structure Trimesh_vertex to an array of float, instead of an array of glm::vec4, but it didn't change anything to my problem. I keep having a black screen. I really don't understand why it works with the array of vertices directly filled in the program, but not from a obj file.
So if anyone has an idea where the mistake is... thanks in advance