我正在尝试让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”但它不起作用
答案 0 :(得分: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();
}