I'm working on a c++Shell, and I'm using OpenGL as the interface for creating the window and drawing text to screen...yes I know this is circuitous, but I'm forced to work with it as it's the only API I know. Now, my problem is in in the glutDisplayFunc()...This is a callback function, and I've got it encapsulated in a class. Now I know the trick to get it to work with a member function is using a static wrapper member function. Here's where the problem comes in. I've got another class for IO, which is being synced with the graphics class...The variables synced are needed for output...which is the whole point of the glutDisplayFunc()...So. I ask of you all, how do I pass these values to the new object created in the wrapper function?
Here's the code that's necessary for answering my questions.
class Graphics{
private:
GLFONT *glFont;
char *user; //user out string
char *system; //system out string
char *error; //error string
char *buffer;
float x; //x Coordinate of text
float y; //y coordinate of text
int runLevel; //0=NULL, 1=User, 2=System, 3=Error
int errLevel; //Levels are listed in '#ifdef ERROR' tree
int sysLevel; //Levels are listed in '#ifdef SYSTEM' tree
public:
int glFontCreate(GLFONT *Font, char *FileName, int Tex); //Intial Creation of Font
void glFontDestroy (GLFONT *Font); //Destruction of Font
void glFontBegin (GLFONT *Font); //Initializer for Font output
void glFontEnd (void); //Destructor for Font Output
void glFontTextOut (char *String, float x, float y,float z); //Font output function
void initScreen(int argc, char **argv); //Initialize gl screen for ooutput
void updateScreen(void); //Updates screen with text typed by user, or output by console.
staticvoid wrapUpdate(void* ptr2Obj);
void passString(char *inBuffer);
void setRunLevel(int level); //Sets runlevel to value indicated by level
void setErrLevel(int level); //Assigns Level to errLevel
void setSysLevel(int level);
Graphics();
~Graphics();
};
This is one of the most common techniques used for callbacks:
1 2 3 4 5 6 7 8 9 10 11
struct callback_params{
Graphics *ptr2Obj;
//Anything else you need
};
//...
void Graphics::wrapUpdate(void *p){
callback_params *params=(callback_params *)p;
p->ptr2Obj->updateScreen();
}
One thing you need to be careful with: the parameter object has to exist whenever the callback may be called, so sometimes you'll have to create it dynamically.
using this technique I've got a new error: 'error: `void*' is not a pointer-to-object type' as well as the old one. Thank you for your help though, I'm sure I'm doing something wrong...
heh, I understood what you meant :P, and I fixed it immediately after posting. Sorry it's late and I'm a little tired, I'm sure you are too. Even so, I'm getting the same error. I know why I am, glutDisplayFunc() expects a pointer to a function with no arguments. and I have no way arround this, save for scrapping glut, and working with another toolkit :\ As I don't know any others...this may take some time. Care to reccomend one for me? It doesn't have to be OpenGL, as I'm learning something new anyways.
Nevermind. Going with X11, I always have liked it. Thank you again for your help Helios, as always, you've been great :P