GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


normals not working when using vertex arrays by Nuticulus
void Octree::GenerateList()
{
    extern unsigned list_counter;
    int i,j,k;
    float *verts,*normals;
    
    list_id = list_counter++;
    verts = new float[vTriangle.size()*9];
    normals = new float[vTriangle.size()*3];
    for(i=0,j=0,k=0;i<vTriangle.size();++i)
    {
        verts[j++]   = vTriangle[i].a.x;     verts[j++]   = vTriangle[i].a.y;     verts[j++]   = vTriangle[i].a.z;
        verts[j++]   = vTriangle[i].b.x;     verts[j++]   = vTriangle[i].b.y;    verts[j++]   = vTriangle[i].b.z;
        verts[j++]   = vTriangle[i].c.x;     verts[j++]   = vTriangle[i].c.y;     verts[j++]   = vTriangle[i].c.z;            
        normals[k++] = vTriangle[i].n.x;    normals[k++] = vTriangle[i].n.y;     normals[k++] = vTriangle[i].n.z;
    }
    
    glNewList(list_id, GL_COMPILE);
        glColor3ub(0, 255, 0);
        
        /*glBegin(GL_TRIANGLES);
        for(i=0;i<vTriangle.size();++i)
        {
            glNormal3f(vTriangle[i].n.x, vTriangle[i].n.y, vTriangle[i].n.z);
            glVertex3f(vTriangle[i].a.x, vTriangle[i].a.y, vTriangle[i].a.z);
            glVertex3f(vTriangle[i].b.x, vTriangle[i].b.y, vTriangle[i].b.z);
            glVertex3f(vTriangle[i].c.x, vTriangle[i].c.y, vTriangle[i].c.z);            
        }
        glEnd(); <-- old code, worked fine
        */
        
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, verts);
        glEnableClientState(GL_NORMAL_ARRAY);
        glNormalPointer(GL_FLOAT, 0, normals);
        
        glDrawArrays(GL_TRIANGLES, 0, vTriangle.size()*3);
        //printf("Done generating list #%u for %d polygons.\n", list_id, vTriangle.size());    
    glEndList();
    
    delete verts, normals;
}