我自己做了一个三维图形编辑器,在菜单项中有打开文件,通过从文件中读出数据,在工作区显示图形,但是按下“打开”按钮后,弹出对话框,选择了文件,确定后,却没有图形显示出来,请问高人如何解决??
解决方案 »
- MFC 串口通信发送16位的数据
- MFC+opengl中纹理对象的作用域???
- 什么是sink?
- ADO 与SQL server 的联接问题,很简单
- 为什么这段代码编译时候没有错,但是不能运行.关于线程的
- 急,请教tree控件和静态文本框有关问题!!
- 感谢Richard2001(Richard) ,可我还是无法VB下调用DLL,紧急求援各位高手
- 用GetDocument得到的IE文档对象有没有tag
- 如何设置系统的路径参数,使我能应NMAKE编译代理DLL
- CString类的Replace函数air\001\t 002中\,\t符号替换成x//怎么不行呢?
- 使用InternetOpenUrl时,错误码12006,是什么原因???
- 一个让我困惑好几天的问题,请大虾帮我!
void COpenGLPlatView::OnFileOpen()
{
// TODO: Add your command handler code here
m_bOpenFile=TRUE;
CFileDialog dlg(TRUE,NULL,"*.txt");
int result=dlg.DoModal();
if(result==IDOK)
{
CString path=dlg.GetPathName();
CStdioFile file(path,CFile::modeRead);
CString str;
BOOL noEOF=TRUE;
this->DrawPolygon();
m_stringArray.RemoveAll();
do
{
noEOF=file.ReadString(str);
if (noEOF) m_stringArray.Add(str);
} while(noEOF);
file.Close();
SetTile(path);
}
UpdateAllViews(0);
}//读文件的函数(单独运行时可读出文件中的数据,但是不知怎么对应上面的菜单命令) FILE *fp1;
if((fp1 = fopen("heart.txt","r")) == NULL)
{
return;
}
int num_vertex;//顶点数 char string[266],a,b,c,d,e,f,g,h;
fgets(string,100,fp1);
while(string[0]=='%'||string[0]=='#')
{
fgets(string,100,fp1);
}
num_vertex=string[3]-48;
for(int i=1;string[3+i]!=32;i++) //字符串转化为整数
{
num_vertex=num_vertex*10+string[3+i]-48;
}
GLfloat vertexSet[100][3]; //点坐标数组
GLfloat x,y,z;
for(int j=0;j<num_vertex;j++)
{
fscanf(fp1,"%c%c%f%c%f%c%f%c",&a,&b,&x,&c,&y,&d,&z,&e);
vertexSet[j][0]=x/5;
vertexSet[j][1]=y/5;
vertexSet[j][2]=z/5;
} int num_face;//面数
//
fgets(string,100,fp1);
while(string[0]=='%'||string[0]=='#')
{
fgets(string,100,fp1);
}
num_face=string[3]-48;
for(int k1=1;string[3+k1]!=32;k1++) //字符串转化为整数
{
num_face=num_face*10+string[3+k1]-48;
}
int faceSet[100][4]; //面数组
int f1,f2,f3,f4; //面的顶点
for (int i1=0;i1<2;i1++)
{
fgets(string,100,fp1);
fscanf(fp1,"%c%c%d%c%d%c%d%c%d%c",&a,&b,&f1,&c,&f2,&d,&f3,&e,&f4,&f);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POLYGON);
glVertex4f(vertexSet[f1][0],vertexSet[f1][1],vertexSet[f1][2],N);
glVertex4f(vertexSet[f2][0],vertexSet[f2][1],vertexSet[f2][2],N);
glVertex4f(vertexSet[f3][0],vertexSet[f3][1],vertexSet[f3][2],N);
glVertex4f(vertexSet[f4][0],vertexSet[f4][1],vertexSet[f4][2],N);
glEnd();
} for(int i2=0;i2<10;i2++)
{
fgets(string,100,fp1);
fscanf(fp1,"%c%c%d%c%d%c%d%c",&a,&b,&f1,&c,&f2,&d,&f3,&e);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POLYGON);
glVertex4f(vertexSet[f1][0],vertexSet[f1][1],vertexSet[f1][2],N);
glVertex4f(vertexSet[f2][0],vertexSet[f2][1],vertexSet[f2][2],N);
glVertex4f(vertexSet[f3][0],vertexSet[f3][1],vertexSet[f3][2],N);
glEnd();
} int num_edge;//边数
//
fgets(string,100,fp1);
while(string[0]=='%'||string[0]=='#')
{
fgets(string,100,fp1);
} num_edge=string[3]-48;
for(int k=1;string[3+k]!=32;k++) //字符串转化为整数
{
num_edge=num_edge*10+string[3+k]-48;
}
//printf("边数:%d\n",num_edge);
int edgeSet[100][2]; //边数组
int Edge_begin,Edge_end; //边的起终点
glColor3f(0.0f,1.0f,0.0f);
glLineWidth(3.0f);
glBegin(GL_LINES); for(int m=0;m<num_edge;m++)
{
fscanf(fp1,"%c%c%d%c%d%c",&a,&b,&Edge_begin,&c,&Edge_end,&d);
glVertex3fv(vertexSet[Edge_begin]);
glVertex3fv(vertexSet[Edge_end]);
}
glEnd(); }