2010-09-26 60 views
1

我試圖讓OpenGL畫出我正在加載的圖形OPENFILENAME。我現在所擁有的是:我可以顯示評論,頂點,多少面孔等,但是我無法畫出圖形,我不知道該怎麼做。我可以畫出其他預定的數字,但不是我想要打開的數字。如何在OpenGL中顯示/繪製.ply對象?


這就是我的一切初始化:

case WM_CREATE: 
    hDC = GetDC(hWnd); 
     hRC=wglCreateContext(hDC); 
     wglMakeCurrent(hDC,hRC); 
     g_hwndDlg = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hWnd,DialogProc); 
     Figure = new DrawFigure(); 
     initGL(); 
     break; 

這是我找出我開的元素有:

/* go through each kind of element that we learned is in the file */ 
    /* and read them */ 

    for (i = 0; i < nelems; i++) { 
    /* get the description of the first element */ 
    elem_name = elist[i]; 
    plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops); 
    int el=sprintf(szFile,"element %s %d\n", elem_name, num_elems); 
    /* print the name of the element, for debugging */ 
     TextOut(hDC,150,0+i*20,szFile,el); 
    /* if we're on vertex elements, read them in */ 
    if (equal_strings ("vertex", elem_name)) { 
     /* create a vertex list to hold all the vertices */ 
     vlist = (Vertex **) malloc (sizeof (Vertex *) * num_elems); 
     /* set up for getting vertex elements */ 
     ply_get_property (ply, elem_name, &vert_props[0]); 
     ply_get_property (ply, elem_name, &vert_props[1]); 
     ply_get_property (ply, elem_name, &vert_props[2]); 


/* grab all the vertex elements */ 
     for (j = 0; j < num_elems; j++) { 
     int move=10; 
     /* grab and element from the file */ 
     vlist[j] = (Vertex *) malloc (sizeof (Vertex)); 
     ply_get_element (ply, (void *) vlist[j]); 


     int vert=sprintf(szFile,"vertex: %g %g %g", vlist[j]->x, vlist[j]->y, vlist[j]->z); 
     /* print out vertex x,y,z for debugging */ 
     TextOut(hDC,600,move+j*20,szFile,vert); 

     Figure->Parameters(vlist[j]->x, vlist[j]->y, vlist[j]->z); 
     } 
    } 

而這正是該類圖是,在那裏我suppossed繪製一切:

Figure::Figure(){ 
} 
void Figure::Parameters(float x,float y,float z) 
{ 
    this->x1=x; 
    this->y1=y; 
    this->z1=z; 
} 
void Figure::Draw() 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glLoadIdentity(); 
    gluLookAt(0.0,0.0,4.0,0.0,0.0,0.0,0.0,1.0,0.0); 

    glBegin(GL_TRIANGLES); 

    glNormal3f(x1,y1,z1); 

    glVertex3f(x1,y1,z1); 
    glEnd(); 
} 
x1,y1,z1 are declared in Figure.h 

我試着盡我所能解釋自己;如果你認爲它仍然需要更多的解釋,請告訴我,我會嘗試以不同的方式解釋它

是的,我忘了解釋我猜想我想畫的圖...我沒有知道哪個數字,因爲我使用OPENFILENAME打開1個隨機數字並繪製它我使用三角形,因爲我認爲用三角形我可以繪製任何東西,而且我在課堂上試過參數要求的頂點數目我是在課堂上處理並做出「for」畫但不起作用

回答

3

您只在開始/結束之間指定一個頂點..您至少需要3個指定三角形。還有更多,如果你想要一個整個buncha三角形。您需要沿着這行更多的東西:

void Figure::Parameters(float x, float y, float z) 
{ 
    m_vertices.push_back(myVertex(x, y, z)); 
} 

void Figure::Draw() 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glLoadIdentity(); 
    gluLookAt(0.0,0.0,4.0,0.0,0.0,0.0,0.0,1.0,0.0); 

    glBegin(GL_TRIANGLES); 

    assert(m_vertices.size() % 3 == 0); // since we're drawing triangles 
    for(size_t i=0; i<m_vertices.size(); i++) 
    { 
     glNormal3f(m_vertices[i].x,m_vertices[i].y,m_vertices[i].z); 
     glVertex3f(m_vertices[i].x,m_vertices[i].y,m_vertices[i].z); 
    } 

    glEnd(); 
} 
+0

耶的事情是我不知道,如果它的將是一個三角形它可以是任何數字:硅還試圖把它像這樣(i = 0;我<數字;我++){glBegin(GL_TRIANGLES); glNormal3f(x1,y1,z1); glNormal3f(x1,y1,z1); glVertex3f(x1,y1,z1); glEnd()}不能讓它工作或者 – Makenshi 2010-09-26 03:45:29

+0

只是不斷傳遞相同的xyz到OpenGL。這將成爲所有頂點都是相同點的三角形。最好的情況下,你看到屏幕上的一個點,最糟糕的情況是,你什麼都看不到。我不熟悉.ply格式,但必須有一個三角形列表,可以是頂點列表或索引頂點列表。這是你應該在你的循環中使用的東西。 – 2010-09-26 05:45:39

+0

是的,我實際上使用了一個頂點列表,並且我嘗試過使用線條,線條,line_loop並且它們都沒有繪製任何東西。< – Makenshi 2010-09-26 06:31:44