Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: rendering md2 model

  1. #1

    rendering md2 model

    Hi,

    I'm trying to make a program that loads and renders an md2 model. I'm getting a blank screen however when everything should look good. I can't see a problem but maybe you guys can. Here's my function to render it, which gets called by my main render function. Also my arrays in the function contain valid data, as my friend gave me the model data to help me debug(he rendered it w/ DX), and i tested the array values against his data print off. here it is:

    bool RenderMD2Model( MD2MODEL *model )
    {
    int i,j;

    GLfloat *verts = new GLfloat[model->NumVerts*3];

    // array to hold entire model vertices
    int vc1=0, vc2=1, vc3=2;
    for(i=0; i < model->NumVerts; i++)
    {
    verts[vc1] = model->Frames[0].Verts[i].x;
    verts[vc2] = model->Frames[0].Verts[i].y;
    verts[vc3] = model->Frames[0].Verts[i].z;
    vc1+=3;vc2+=3;vc3+=3;
    }

    int nTotalNumIndices = 0;
    for(i =0; i < model->NumPrimitives; i++)
    {
    nTotalNumIndices += model->Primitives[i].NumFaceIndices;
    }

    GLubyte *indices = new GLubyte[nTotalNumIndices];

    // big array to hold all the indices
    int ic1 = 0;
    for(i=0; i < model->NumPrimitives; i++)
    {
    for(j=0; j < model->Primitives[i].NumFaceIndices; j++)
    {
    indices[ic1] = model->Primitives[i].FaceIndices[j].index;
    ic1++;
    }
    }

    // draw it!
    // Enable the vertex array
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, verts);
    glDrawElements(GL_TRIANGLE_STRIP, nTotalNumIndices, GL_UNSIGNED_BYTE, indices);

    delete [] verts; verts = NULL;
    delete [] indices; indices = NULL;

    return true;

    }

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    england, uk
    Posts
    3

    Re: rendering md2 model

    I wrote a program to draw an md2model a while ago, and unfortunately I don't have the source to hand. But one thing I remember is that there is a series of gl_cmds which dictate whether a number of vertices are to be interpreted as a fan or a strip.

    It went something along the lines of: if the gl_cmd has a value -n then the next n indices make a fan, if the gl_cmd has value +n then the next n indices make a strip. Or vice-versa, or something along those lines?

    Sorry I can't be more helpful.

    Andy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •