0

C ++でglutを使用して、メイン関数に入力したファイルの情報に基づいて図面を作成しようとしています。

int main (int argc, char** argv)  //I think this is all relevant info in main
{   
glutDisplayFunc (display);

fstream file = fstream ("Tree.txt");
Tree myTree = Tree(file);
}

static    //this is the function I need to draw from but it can't take any parameters
void display(void)
{  
}

static void draw_frame(Tree::Node* t) //my draw function needs access to info from my file stream
{
    int x = t->xValue;  //for example I need to access these variables
    int y = t->yValue;
}

Tree * myTreeをグローバル変数にしようとしましたが、エラーが増え、ファイルの読み取りが完全に停止しました。誰かアイデアがあれば、とてもありがたいです!

4

1 に答える 1

0

あなたの場合、 Tree をグローバル変数として配置する必要があります。「ツリー構築」コードをコンストラクターから移動し、メイン関数から初期化することをお勧めします。次のようなもの:

Tree GTree;
int main (int argc, char** argv)  //I think this is all relevant info in main
{   
    glutDisplayFunc (display);

    fstream file = fstream ("Tree.txt");
    GTree.Initialize(file);
}

次に、displayレンダリングに GTree を使用できます。

レンダリングを更新する必要がある場合は、glutPostRedisplayを呼び出すか、または glutIdleFunc を使用する必要があることに注意してくださいdisplay

于 2012-11-14T19:08:03.013 に答える