I am trying to draw a model that I loaded into memory using a custom format. I think it might have to do with the way I'm handling textures. I'm not getting any GLSL errors. These are the two functions I use that deal with loading and drawing the model
/**************************************************
Model object has the following functions to load
and to draw:
**************************************************/
bool Model::loadModel(const std::string& fname, GLuint pgm_id){
ModelTexture* texture = nullptr;
unsigned int vbo_size = 0;
unsigned int tbo_size = 0;
program_id = pgm_id;
if(!BPFImporter::importBPFModel(fname,data)){
return false;
}
vbos.resize(data.file_header.object_count);
glGenBuffers(data.file_header.object_count, &vbos.front());
for(unsigned int obj = 0; obj < data.file_header.object_count; obj++){
vbo_size = data.objects.at(obj).object_header.vertex_count*sizeof(ModelVertex);
glBindBuffer(GL_ARRAY_BUFFER, vbos.at(obj));
if(data.objects.at(obj).object_header.animated_flag != 0){
glBufferData(GL_ARRAY_BUFFER,vbo_size,&data.objects.at(obj).vertices.front(),GL_STREAM_DRAW);
}else{
glBufferData(GL_ARRAY_BUFFER,vbo_size,&data.objects.at(obj).vertices.front(),GL_STATIC_DRAW);
}
}
tbos.resize(data.file_header.material_count);
glGenTextures(data.file_header.material_count, &tbos.front());
//store appropriate textures... (only does first texture of every material...)
for(unsigned int mat = 0; mat < data.file_header.material_count; mat++){
texture = &data.materials.at(mat).textures.front();
glBindTexture(GL_TEXTURE_2D, tbos.at(mat));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
texture->texture_header.width,
texture->texture_header.height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
&texture->texels.front());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
return true;
}
void Model::drawModel(){
ModelObjectHeader *object_header;
std::vector<ModelFace> *faces;
glUseProgram(program_id);
for(unsigned int obj = 0; obj < data.file_header.object_count; obj++){
object_header = &data.objects.at(obj).object_header;
faces = &data.objects.at(obj).faces;
glBindBuffer(GL_ARRAY_BUFFER,vbos.at(obj));
glBindTexture(GL_TEXTURE_2D, tbos.front());
//setup vertex position pointer
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,4,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)COORD_OFFSET);
//setup vertex normal pointer
glEnableVertexAttribArray(1);
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)NORMAL_OFFSET);
//setup vertex texture pointer
glEnableVertexAttribArray(2);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,sizeof(ModelVertex),(void*)TEXTURE_OFFSET);
glDrawElements(GL_TRIANGLES, object_header->face_count,GL_UNSIGNED_BYTE, (void*)&faces->front());
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
}
return;
}
The model is just a simple crate with one texture. Something easy to test values on. I've printed out and checked the texel values too and they are correct. I matched the rgba values to what I get in gimp. They all match.