Exemplo n.º 1
0
int main(int argc,char** argv)
{
    initOGL(argc,argv);
    glutDisplayFunc(draw_stuff);
    glutMainLoop();
    return 0;
}
HRESULT OGLTest::Init(HINSTANCE hInstance,
                      LPSTR lpCmdLine,
                      int nCmdShow)
{
    parseCmdLine(lpCmdLine);

    HRESULT hr = initWindow(hInstance, nCmdShow);
    if (SUCCEEDED(hr))
    {
        mpRender = CreateRender(miRenderId);
        if (mpRender)
        {
            hr = initOGL();
            if (SUCCEEDED(hr))
            {
                setCurrentGLCtx(mhGLRC);

                hr = mpRender->InitRender();
                if (FAILED(hr))
                {
                    TestShowError(hr, "InitRender");
                }

                setCurrentGLCtx(NULL);
            }
        }
        else
        {
            hr = E_FAIL;
        }
    }

    return hr;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
initOGL(argc,argv);
glutDisplayFunc(draw_stuff);
glutIdleFunc(update);
glutKeyboardFunc(getout);
glutMainLoop();
return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    
    if(argc < 2){
        std::cout<<"need file name"<< std::endl;
        exit(1);
    }
    

    float *vHead;
    char *fHead;
    char *buffer = readFlyFile(argv[1], &vertexNum, &faceNum, &vHead, &fHead);
    
    printf("%f\n", *(vHead));
    printf("%d\n", *fHead);
    
    std::cout<<vertexNum<<" "<<faceNum<<std::endl;
    
    Vertex *vertices = new Vertex[vertexNum];
    Face *faces = new Face[faceNum]; 
    float MAX = 0, aveX=0, aveY=0, aveZ=0;
    
    for (int i=0; i<vertexNum; ++i) {
        float x = *(vHead+3*i+0);
        float y = *(vHead+3*i+1);
        float z = *(vHead+3*i+2);
        MAX = max(max(max(x, y), z),MAX);
        aveX += x;
        aveY += y;
        aveZ += z;
    }
    aveX /= vertexNum;
    aveY /= vertexNum;
    aveZ /= vertexNum;
    
    for (int i=0; i<vertexNum; ++i) {
        vertices[i].vert.x = (*(vHead+3*i+0) - aveX) /(MAX) * 3;
        vertices[i].vert.y = (*(vHead+3*i+1) - aveY) /(MAX) * 3;
        vertices[i].vert.z = (*(vHead+3*i+2) - aveZ) /(MAX) * 3;
    }
    
    for (int i=0; i<faceNum; ++i) {
        int v1 = *((int *)(fHead+13*i+1));
        int v2 = *((int *)(fHead+13*i+5));
        int v3 = *((int *)(fHead+13*i+9));
        
        if (v1>vertexNum || v1<0) {
            std::cout<<"index error: "<<v1<<"i: "<<i<<std::endl;
            exit(9);
        }
        faces[i].v1 = v1;
        faces[i].v2 = v2;
        faces[i].v3 = v3;
        Vector3d v1v2 = vertices[v2].vert - vertices[v1].vert;
        Vector3d v1v3 = vertices[v3].vert - vertices[v1].vert;
        Vector3d normtmp = (v1v2 % v1v3).normalize();
        Vector3d center = (v1+v2+v3)/3.0;
        if (normtmp * center > 0) {
            faces[i].normal = normtmp;
        }
        else{
            faces[i].normal = -1.0 * normtmp;
        }
    }
    
	/*    
    for (int i=1; i<10; ++i) {
        std::cout<<vertices[i].vert<<"\n";
        std::cout<<faces[i].v1<<" "<<faces[i].v2<<" "<<faces[i].v3<<"\n";
        std::cout<<faces[i].normal<<std::endl;
    }
    */
    long bufSize = 3*3*faceNum*2; // 1face: 3vertices*3floats*4bytes
    long normBase = 3*3*faceNum;
    GLfloat* vertsBuff = new GLfloat[bufSize];
    std::cout<<bufSize<<"\n";
    for (int i=0; i<faceNum; ++i) {
        vertsBuff[i*9+0] = vertices[faces[i].v1].vert.x;
        vertsBuff[i*9+1] = vertices[faces[i].v1].vert.y;
        vertsBuff[i*9+2] = vertices[faces[i].v1].vert.z;
        vertsBuff[i*9+3] = vertices[faces[i].v2].vert.x;
        vertsBuff[i*9+4] = vertices[faces[i].v2].vert.y;
        vertsBuff[i*9+5] = vertices[faces[i].v2].vert.z;
        vertsBuff[i*9+6] = vertices[faces[i].v3].vert.x;
        vertsBuff[i*9+7] = vertices[faces[i].v3].vert.y;
        vertsBuff[i*9+8] = vertices[faces[i].v3].vert.z;
        vertsBuff[normBase + i*9+0] = faces[i].normal.x;
        vertsBuff[normBase + i*9+1] = faces[i].normal.y;
        vertsBuff[normBase + i*9+2] = faces[i].normal.z;
        vertsBuff[normBase + i*9+3] = faces[i].normal.x;
        vertsBuff[normBase + i*9+4] = faces[i].normal.y;
        vertsBuff[normBase + i*9+5] = faces[i].normal.z;
        vertsBuff[normBase + i*9+6] = faces[i].normal.x;
        vertsBuff[normBase + i*9+7] = faces[i].normal.y;
        vertsBuff[normBase + i*9+8] = faces[i].normal.z;
    }
    
    
    initOGL(argc,argv, vertsBuff);
    glutDisplayFunc(draw_stuff);
    glutIdleFunc(update);
    glutKeyboardFunc(getout);
    glutMainLoop();
    
    delete [] buffer;
    delete [] vertsBuff;
    delete [] faces;
    delete [] vertices;
    return 0;
    
}