c++ Glut 显示需要调用我的绘制函数,但我无法传递任何参数
c++ Glut display needs to call my draw function but I can't pass any parameters
我正在尝试在 c++ 中使用 glut 根据我输入到 main 函数中的文件中的信息来创建绘图。
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 设置为全局变量,但我只是遇到了更多错误,它会完全停止读取我的文件。 如果有人有任何想法,我将不胜感激!
在您的情况下,您需要将 Tree 作为全局变量。我建议从构造函数中移动您的"树构建"代码,并从 main 函数初始化它。大致如下:
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 或将display
作为 glutIdleFunc
相关文章:
- 用于检查值是否为其任何参数的帮助程序函数
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- 如何制作可以接受任何类型的参数的 std::函数和 lambda
- MSVC 错误:4 个重载中的任何一个都无法转换所有参数类型
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- 使用聚合初始化模拟默认函数参数是否存在任何陷阱?
- 在将匿名对象作为参数传递时,不会调用任何构造函数
- 此函数如何在不传递任何参数的情况下工作?
- 高效的可变参数等于任何函数
- 如何声明一个接受任何大小的 2D 矢量参数?
- 如何在C++中接收任何类型的函数参数并获取函数内传递变量的类型?
- 在参数相关查找之前进行模板替换的任何方法(或解决方法?
- 部分专用化不使用其任何模板参数
- 创建一个构造函数,即Capabe获取任何数量的参数
- C++任何非类型参数的模板专用化
- 有没有办法跟踪任何编译器的模板参数推导?
- C 模板功能是否有任何方法可以采用n个参数
- 类介绍 (c++) 项目希望我们创建两个构造函数,但它们都不需要任何参数 - 我应该在这里做什么?
- 创建带有任何参数的 std::functions 的unordered_map?
- 将任何数据类型/对象作为参数传递以确定其大小