I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.
Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:
glm::vec2 points[6] =
{
glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
};
std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
for(int i = 0; i<6; i++)
{
fs.write((const char*)&points[i].x, sizeof(points[i].x));
fs.write((const char*)&points[i].y, sizeof(points[i].y));
}
fs.close();
and here is the code for copying the data into the vbo:
int length;
char* data;
ifstream is;
is.open("model.bin", ios::binary);
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(0, ios::beg);
data = new char[length];
is.read(data, length);
is.close();
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?