曾经的glDrawArrays代码

void IGLArea::Prepair_glDrawArrays()//准备好glDrawArrays
{

    printf("IGLArea::Prepair_glDrawArrays()------1\n");
    double max_z=GlobVar::pMesh->GetVolumnInfo().max_z;
    double min_z=GlobVar::pMesh->GetVolumnInfo().min_z;
    printf("IGLArea::Prepair_glDrawArrays()------2\n");

    double l=(GlobVar::systemSettings->lowerValueForShow/100.0)*(max_z-min_z)+min_z;
    double u=(GlobVar::systemSettings->upperValueForShow/100.0)*(max_z-min_z)+min_z;
    printf("IGLArea::Prepair_glDrawArrays()------3\n");

    //------------------------------------------------
    //第一步:准备顶点数据
    //------------------------------------------------

    int n=GlobVar::pMesh->GetTrianglsNumber();
    printf("IGLArea::Prepair_glDrawArrays()------4\n");

    p_vertex = new float[n*30];
    printf("IGLArea::Prepair_glDrawArrays()------5\n");


    //下面两句是为了客服引用和指针之间的关系
    const vector<Triangle>* tmp=GlobVar::pMesh->GetTriangles();
    const vector<Triangle>& triangles=(*tmp);

    const vector<Point3D>* tmp1=GlobVar::pMesh->GetNormals();
    const vector<Point3D>& normals=(*tmp1);
    printf("IGLArea::Prepair_glDrawArrays()------6\n");

    int i=0;
    for(int j=0;j<GlobVar::pMesh->GetTrianglsNumber();j++)
    {
        Point3D p0=triangles[j].p0;
        Point3D p1=triangles[j].p1;
        Point3D p2=triangles[j].p2;
        Point3D normal=normals[j];

        //color


        float value_=p0.Z();
        float z=GeometryTools::normalizeZByMinMax(u,l,value_);//z is in 0.0~1.0
        //z=0.5;
        const tinycolormap::Color color = tinycolormap::GetColor(z, tinycolormap::ColormapType::Heat);


        p_vertex[i+0]=p0.X();
        p_vertex[i+1]=p0.Y();
        p_vertex[i+2]=p0.Z();

        p_vertex[i+3]=color.r();;
        p_vertex[i+4]=color.g();;
        p_vertex[i+5]=color.b();;
        p_vertex[i+6]=1.0;

        p_vertex[i+7]=normal.X();
        p_vertex[i+8]=normal.Y();
        p_vertex[i+9]=normal.Z();


        //color
        value_=p1.Z();
        z=GeometryTools::normalizeZByMinMax(u,l,value_);//z is in 0.0~1.0
        //z=0.5;

        const tinycolormap::Color color1 = tinycolormap::GetColor(z, tinycolormap::ColormapType::Heat);


        p_vertex[i+10]=p1.X();
        p_vertex[i+11]=p1.Y();
        p_vertex[i+12]=p1.Z();

        p_vertex[i+13]=color1.r();;
        p_vertex[i+14]=color1.g();;
        p_vertex[i+15]=color1.b();;
        p_vertex[i+16]=1.0;

        p_vertex[i+17]=normal.X();
        p_vertex[i+18]=normal.Y();
        p_vertex[i+19]=normal.Z();

        //color

        value_=p2.Z();
        z=GeometryTools::normalizeZByMinMax(u,l,value_);//z is in 0.0~1.0
        //z=0.5;
        const tinycolormap::Color color2 = tinycolormap::GetColor(z, tinycolormap::ColormapType::Heat);


        p_vertex[i+20]=p2.X();
        p_vertex[i+21]=p2.Y();
        p_vertex[i+22]=p2.Z();

        p_vertex[i+23]=color2.r();;
        p_vertex[i+24]=color2.g();;
        p_vertex[i+25]=color2.b();;
        p_vertex[i+26]=1.0;

        p_vertex[i+27]=normal.X();
        p_vertex[i+28]=normal.Y();
        p_vertex[i+29]=normal.Z();

        i+=30;
    }

    printf("IGLArea::Prepair_glDrawArrays()------7\n");


    //------------------------------------------------
    //第二步:定点数据放入缓冲区
    //------------------------------------------------
    glewInit();    //因为windows对opengl的支持不好,为了不使用软模拟的opengl,需要从显卡厂家的驱动里抽取opengl的实现,
    //而glew方便了这个过程。只需要调用一下glewInit就可以使用gl*函数了。

    printf("IGLArea::Prepair_glDrawArrays()------8\n");



    //首先删除缓冲区,如果缓冲区不存在,也不报错
    glDeleteBuffers(1,&vboId);

    //分配vbo句柄
    glGenBuffers(1,&vboId);

    //GL_ARRAY_BUFFER表示作为顶点数组解析
    glBindBuffer(GL_ARRAY_BUFFER,vboId);

    //拷贝数据
    glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*n*3*10,
                 p_vertex,GL_STATIC_DRAW);


    printf("IGLArea::Prepair_glDrawArrays()------9\n");



}

 

 

 

void IGLArea::DrawMesh_GraphicsMem()//绘制缓冲区中mesh顶点数据
{




    if(0==(GlobVar::pMesh->MatPoints.size()))
    {
        return;
    }


    if(0==(GlobVar::pMesh->GetTrianglsNumber()))
    {
        return;
    }


    int n=GlobVar::pMesh->GetTrianglsNumber();



    glEnableClientState(GL_VERTEX_ARRAY);//启用顶点数组属性
    glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*10, 0);//如何解析vbo中数据


    glEnableClientState(GL_COLOR_ARRAY);//启用顶点数组属性
    glColorPointer (4, GL_FLOAT, sizeof(GLfloat)*10,     (GLuint*) (sizeof(GLfloat)*3)    );


    glEnableClientState(GL_NORMAL_ARRAY);//启用顶点数组属性
    glNormalPointer(GL_FLOAT,sizeof(GLfloat)*10, (GLuint*) (sizeof(GLfloat)*7) );



  glDrawArrays(GL_TRIANGLES, 0, n*3);//最后一个参数,是顶点的个数
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值