not using texture right? model not drawing

Started by
3 comments, last by dpadam450 10 years, 1 month ago

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;
}
I've tested data in the structures that hold the model data. This is what I got printed out:

Object[0]
---------
Object Header
-------------
vertex_count:24
face_count:12
material_index:0
coord_flag:1
color_flag:0
normal_flag:1
texture_flag:1
animated_flag:0
Vertex Positions
----------------
1,1,-1,1
1,-1,-1,1
-1,-1,-1,1
-1,1,-1,1
1,0.999999,1,1
-1,1,1,1
-1,-1,1,1
0.999999,-1,1,1
1,1,-1,1
1,0.999999,1,1
0.999999,-1,1,1
1,-1,-1,1
1,-1,-1,1
0.999999,-1,1,1
-1,-1,1,1
-1,-1,-1,1
-1,-1,-1,1
-1,-1,1,1
-1,1,1,1
-1,1,-1,1
1,0.999999,1,1
1,1,-1,1
-1,1,-1,1
-1,1,1,1
Vertex Normals
--------------
0.666667,0.333333,-0.666667
0.408248,-0.816497,-0.408248
-0.666667,-0.333333,-0.666667
-0.408248,0.816497,-0.408248
0.333333,0.666666,0.666667
-0.816496,0.408249,0.408248
-0.333333,-0.666667,0.666667
0.816496,-0.408249,0.408248
0.666667,0.333333,-0.666667
0.333333,0.666666,0.666667
0.816496,-0.408249,0.408248
0.408248,-0.816497,-0.408248
0.408248,-0.816497,-0.408248
0.816496,-0.408249,0.408248
-0.333333,-0.666667,0.666667
-0.666667,-0.333333,-0.666667
-0.666667,-0.333333,-0.666667
-0.333333,-0.666667,0.666667
-0.816496,0.408249,0.408248
-0.408248,0.816497,-0.408248
0.333333,0.666666,0.666667
0.666667,0.333333,-0.666667
-0.408248,0.816497,-0.408248
-0.816496,0.408249,0.408248
Vertex TCoords
--------------
0.9999,0.9999
0.0001,0.0001
0.0001,0.0001
0.9999,0.9999
0.9999,0.9999
0.0001,0.0001
0.0001,0.0001
0.999899,0.999899
0.9999,0.9999
0.9999,0.9999
0.0001,0.0001
0.0001,0.0001
0.9999,0.9999
0.9999,0.9999
0.0001,0.0001
0.0001,0.0001
0.0001,0.0001
0.0001,0.0001
0.9999,0.9999
0.9999,0.9999
0.9999,0.9999
0.9999,0.9999
0.0001,0.0001
0.0001,0.0001
/**********************************************************
data.objects.at(obj).faces contains the following:
**********************************************************/
Vertex Indices
--------------
0,1,2
0,2,3
4,5,6
4,6,7
8,9,10
8,10,11
12,13,14
12,14,15
16,17,18
16,18,19
20,21,22
20,22,23

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.

Advertisement

You don't need to store the w coordinate for your positions, just xyz.

Are you using a version of opengl that you can call glVertex3f()? Your question is too broad. Disable the shader and see what you get normally. There are a lot of options, disable the shader, strip out all the normal/tex coord stuff and just deal with positions without a shader.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Ok, I am forcing a OpenGL 3.2 context. Using GLSL 330. I've had models with no textures working in my custom format. But I've done a major reworking of everything to make it cleaner and smoother. The model that was working was just the traditional colored triangle I wrote in my file format by hand using a hex editor. At this point, I decided to write my exporter to export .3ds files to my format. It's completed. I've tested it thoroughly. I wrote a set of importer functions and tested them out and it all gets loaded in the data structures in the same form that I was originally using.

Anyways, I took your suggestion. There are no matrix transformations occuring in my program at the moment. The view, projection and everything hasn't been touched. I'm using a grey colored cube. with dimenions in the range of 1,1,1 to -1,-1,-1. I clear the background to black, and draw this grey cube. Nothing shows up. Is my problem that I'm looking from inside the cube out? Interestingly enough if I turn the background color to something like blue, go into wireframe mode then I can see the polygons of a square. This is what I'd expect. a grey square taking up the entire view... but yeah

What's your viewport setting? Are you sure of the winding order? Are you front or back face culling?

Edit - try translating along the -Z axis, I guess you looking from the inside out.

As you suggested you are in the cube most likely, glTranslatef(0,0,-x), x being in range 1 to maybe 10.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement