我想从文件里读取xyz,但是运行出来却是一片空
```c++
#include<GL/glut.h>
#include<iostream>
#include<cstdio>
char todo[1001];
float startx,starty,startz,endx,endy,endz;
using namespace std;
void get(){
freopen("main.txt","r",stdin);
cin>>todo>>startx>>starty>>startz>>endx>>endy>>endz;
fclose(stdin);
}
// 初始化参数
void init() {
glClearColor(0.1, 0.1, 0.4, 0.0);
glShadeModel(GL_SMOOTH);
}
// 绘图回调函数
void display() {
cout<<startx<<endz;
// 清除之前帧数据
glClear(GL_COLOR_BUFFER_BIT);
// 绘制三角形
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(startx,starty,startz);
glColor3f(0, 1, 0);
glVertex3f(endx,starty,startz);
glColor3f(0, 0, 1);
glVertex3f(endx,endy,startz);
glColor3f(0, 0, 1);
glVertex3f(startx,endy,startz);
glEnd();
// 执行绘图命令
glFlush();
}
// 窗口大小变化回调函数
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.1, 100000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, const char * argv[]) {
get();
// 初始化显示模式
glutInit(&argc, const_cast<char **>(argv));
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// 初始化窗口
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
// 开始主循环绘制
glutMainLoop();
return 0;
}
结果:
我尝试着更换数据类型,但没有效果
我想要把图形显示出来
main.txt的内容是Box 0 0 0 20 20 20