Another attemp to hack OpenGL

The task is still super simple, but OpenGL is not.
Output VARIABLE text message to OpenGL basic window.
The “problem” - callback functions do not accept parameters…so how do I output variable message ?

Here is a solution some other fellow came up with TEN years ago !
( IMHO Reopening that thread woudl be pointless)

I understand the “global function prototypes”, the usage of class, but I am still getting “static” issue errors.

  1. I do no get WHERE to “Assign these functions to glut’s callbacks (here) :”

Can anybody help me starting with this step ???

Again , if detailed / basic OpenGL /C++questions are not welcome here, please just ignore my post.

I ran into this problem writing a C++ Glut engine myself. Here’s how I worked around it:

I placed these at the top of my program.cpp / main.cpp

// Function prototypes
void doRendering( void );
void processMouse( int, int ) ;
void processMouseClick(int button, int state, int x, int y);
void keyboardInput(unsigned char c, int x, int y);

Assign these functions to glut’s callbacks here: ??? where ???

glutDisplayFunc(doRendering);
glutIdleFunc(doRendering);
glutPassiveMotionFunc(processMouse);
glutMotionFunc(processMouse);
glutMouseFunc(processMouseClick);
glutKeyboardFunc(keyboardInput);

Create my own class which handles these on its own and then make the contents of our static functions simply call methods on the instance of this class. Your main function should create a new instance of the class in main (in my case… App *newApp).

void doRendering( void )
{
    newApp->updateScene();
    newApp->drawScene();
}

void processMouse(int x, int y)
{
    newApp->processMouse(x, y);
}

void processMouseClick(int button, int state, int x, int y)
{
    newApp->processMouseClick(button, state, x, y);
}

void keyboardInput(unsigned char c, int x, int y)
{
    newApp->keyboardInput(c, x, y);
}

SOLVED ??
How is this for a hack?

char *stringTest = “The quick dog jumps over the lazy brown fox.”;
void display() { // “standard” OpenGL display
// post test message
extern char *stringTest; // hack
glClear(GL_COLOR_BUFFER_BIT);
drawTriangle();
rectangle();
text(stringTest);
glFlush();
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.