传递1个参数(指针)到glutDisplayFunc? [英] Passing 1 argument (pointer) to glutDisplayFunc?

查看:1361
本文介绍了传递1个参数(指针)到glutDisplayFunc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个基本的draw()方法,不做任何事情的虚拟类。这样做的目的是,其他类,形状和其他东西,将能够在OpenGL中绘制自己,将继承这个虚拟类,允许我创建指向许多不同类的指针数组。这背后的想法是,我希望我能够传递一个指向这个数组到我的glutDisplayFunc回调。不幸的是我似乎不能传递任何东西给它,因为glutDisplayFunc是设计为采取一个方法,没有参数,并不返回任何东西。



有什么方法可以传递参数到回调函数,然后任何方式传递指针到我的drawScene函数?



(TLDR? 。)



基本上我想要能够这样做:

  class a {...}; 
void drawScene(a ** a_array_pointer){...}
glutDisplayFunc(drawScene); //< - 如何传递参数到this?


解决方案


传递参数给回调函数,然后任何方式传递一个指针到我的drawScene函数?


库, glutDisplayFunc 期望一个函数指针作为它的参数。在回调中使用变量的唯一方法是使它们成为类的全局变量或静态变量。 p>

I have created a virtual class with a basic draw() method which doesn't do anything. The purpose of this is that other classes, shapes and other stuff, which will be able to draw themselves in OpenGL, will inherit this virtual class, allowing me to create an array of pointers to many different classes. The idea behind this was that I was hoping I would be able to pass a pointer to this array into my glutDisplayFunc callback. (This happens to be named drawScene(). Unfortunately I don't seem to be able to pass anything to it, as glutDisplayFunc is designed to take a method which takes no parameters and return nothing.

Is there any way of passing arguments to callback functions, and then any way of passing a pointer into my drawScene function?

(TLDR? See below.)

Essentially I want to be able to do this:

class a{ ... };
void drawScene( a** a_array_pointer){ ... }
glutDisplayFunc(drawScene); // <-- How do I pass an argument into this?

解决方案

Is there any way of passing arguments to callback functions, and then any way of passing a pointer into my drawScene function?

No. glut is really a C library, and the glutDisplayFunc expects a function pointer as it's parameter. The only way to use variables in that callback, is to make them global or static variables of a class.

这篇关于传递1个参数(指针)到glutDisplayFunc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆