如何在 OpenGL 中显示/绘制 .ply 对象?

发布于 2024-09-25 02:39:56 字数 2641 浏览 4 评论 0原文

我试图让 OpenGL 绘制我正在使用 OPENFILENAME 加载的图形。我现在所得到的是:我可以显示注释、顶点、有多少个面等,但我无法绘制图形,而且我不知道该怎么做。我可以绘制其他预定的图形,但不能绘制我要打开的图形。


这是我初始化所有内容的地方:

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);
      }
    }

这是类图所在的位置,我应该在其中绘制所有内容:

    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 个随机图形并绘制它,我使用了三角形,因为我认为使用三角形我可以绘制任何东西,而且我在类参数中尝试询问我正在处理和制作的顶点数量Draw 类中的“for”,但它不起作用

I'm trying to make OpenGL draw the figure that I'm loading with OPENFILENAME. What I've got right now is: I can display the comments, vertex, how many faces, etc., but I cannot draw the figure and I'm not sure how to do it. I can draw other predetermined figures, but not the ones I'm trying to open.


This is where I'm initializing everything:

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;

This is where I find out what the element I'm opening has:

  /* 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);
      }
    }

And this is where the class Figure is, where I'm suppossed to draw everything:

    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

I tried to explain myself the best I could; if you think it still needs more explanation please tell me and I will try to explain it in a different way

Yeah, I forgot to explain I guess the figure I'm trying to draw...well i don't know which figure it would be because I'm using OPENFILENAME to open 1 random figure and draw it i used triangles because i thought that with triangles i could draw anything and also i tried in the class Parameters ask for the number of vertex I'm dealing with and making a "for" in the class Draw but it didn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窗影残 2024-10-02 02:39:56

您只需指定开始/结束之间的一个顶点。您至少需要 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();
}

You only specify one vertex between your begin/end.. you need at least 3 to specify a triangle. And many more if you want a whole buncha triangles. You need something more along the lines of this:

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文