"Updating OpenGL display "?

I will be using OpenGL to display data on Smith chart.
I thing I got the “callback” concept figured out, now I need to verify how to trigger redraw of the “display”.
Is
glutPostRedisplay();

common way to accomplish that ?

The “update display” will be triggered asynchronously - externally via bluetooth. Basically bluetooth socket waits for data to arrive. So - can I use glutPostRedisplay() AFTER the data arrives? Any issues with process being stopped to wait for the data and OpenGL "main loop "?
I hope this makes sense.

Addendum
No, it does not make sense.
If process is stopped waiting for socket to arrive it woudl have to be inserted in SOME OpenGL loop.
So -have " wait for socket" loop , when data arrives THEN implement ONE shot of OpenGL “main loop” and exit it.
Then loop in "wait for socket state " and when data arrives - repeat the above.
Display timing is irrelevant.

FreeGLUT and OpenGLUT allow you to do this via glutMainLoopEvent, but that function isn’t available in the original GLUT library. glutMainLoopEvent processes all pending events, returning once the event queue is empty.

An alternative approach is to use glutTimerFunc to poll the socket periodically. Either way, you still need to use glutPostRedisplay to trigger redraw; OpenGL rendering functions shouldn’t be called other than from the display callback.

Thanks, but I am sure it is not that simple.
Here my my basic working OpenGL code snippet, adding glutMainLoopEvent(); gives
" error: ‘glutMainLoopEvent’ was not declared in this scope " error.
I need to revisit Framework “wrapper” creation - I am not sure, but it maybe my problemis it may have to be inserted in “idle” callback in first place - glutIdleFunc(runWrapper);
But “not declared” woudl be same issue there.

Also per description glutMainLoopEvent(); "processes " windows,etc. events .
So it is back to how to make it to process my specific event.

setInstance();// Sets the instance to self, used in the callback wrapper functions

// Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(WINDOW_X_POSITION, WINDOW_Y_POSITION);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow(title.c_str());

// Function callbacks with wrapper functions
glutReshapeFunc(reshapeWrapper);
glutMouseFunc(mouseButtonPressWrapper);
glutMotionFunc(mouseMoveWrapper);
glutDisplayFunc(displayWrapper);
glutKeyboardFunc(keyboardDownWrapper);
glutKeyboardUpFunc(keyboardUpWrapper);
glutSpecialFunc(specialKeyboardDownWrapper);
glutSpecialUpFunc(specialKeyboardUpWrapper);

glutMainLoopEvent();

init();						// Initialize
glutIdleFunc(runWrapper); 	// The program run loop
glutMainLoop();				// Start the main GLUT thread

For FreeGLUT, you need

#include <GL/freeglut_ext.h>

Including glut.h only declares the functions which are part of the original GLUT API, not the extensions.

OK, I have updated my headers includes

#ifdef _WIN32
	#include <windows.h>
	#include <GL/glut.h>
#elif __APPLE__
  #include <GLUT/glut.h>
#elif __linux
#include <GL/glut.h>
#include <GL/glu.h>
#endif

#include "Keyboard.h"
#include "PerformanceTimer.h"
#include "Vector.h"

//3/12/2020
#include "GL/freeglut.h"
#include "GL/freeglut_ext.h"
#include "GL/gl.h"

and compiler /linker likes it.

As far as original question
i think the KISS method will be
after socket gets data modify contents of OpenGL “display” and then run single shot of OpenGL.
By single shot I mean to terminate the “main” OpenGL “loop” thus return to application process - to stay in socket monitoring state.

Addendum
OK, I got rid of “OpenGL framework”. Too convoluted.
I am back to really basic OpenGL.

  1. I test put the “main loop” in class constructor AND as a last instruction I have
    glutLeaveMainLoop(); that “terminates” the constructor and lets me execute similar setup in class method.
  2. Now I have TWO windows on desktop and interestingly I can still move the constructor’s one. Eventually I’ll will delete constructor created window, don’t need it.
  3. Now I am going to modify “display” and execute the method created real “window”.

Wish me luck, it should work.

int argc = 1;
char *argv[1] = { (char*) "Something" }; //hack 
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL - Base ");
glutDisplayFunc(drawTriangle);
glutLeaveMainLoop();

I am not sure what is customary on this forum - post new or follow -up.

Here us a follow -up.
This link describes way to control the “main loop”.
http://openglut.sourceforge.net/group__mainloop.html

My objective to run one pass thru the “main loop” and exit it.
Here is my interpretation of the task in code

    ...all callback functions here 
    including "display" ...
glutIdleFunc(runWrapper); 	// The program run loop - exits but no display
//glutMainLoop();			//Normal start of the  main GLUT thread - stays here
glutMainLoopEvent( );      // ? set event to make one pass thru "main loop " - NO DISPLAY 
glutLeaveMainLoop();         // exits OK ,  but no display

What am I missing? Is the "idle function " the issue ?

This doesn’t make sense. You can either:

  1. call glutMainLoopEvent in a loop, or
  2. call glutMainLoop and have a callback call glutLeaveMainLoop to terminate the loop.

glutLeaveMainLoop does nothing if you haven’t called glutMainLoop.

Use option #1 if you already have a main loop, use option #2 if you want GLUT to provide the main loop.

Once you exit the main loop (either yours or GLUT’s), events are no longer processed; one consequence of this is that the window won’t be redrawn in response to expose (paint) events. Any window-based program has to process events continually in order to function.

glutLeaveMainLoop(); does exactly what it implies , but MORE…

it kills the window I have set in originally!

Not what I am after.
I need to stop (leave / exit) the “main loop” so I can CONTINUE running the rest of the application.
I other words - the OpenGL is just a I/O function, NOT the main process.
Once it is used I have no need for further “main loop processing”.

I am open to suggestion how to accomplish that.

I prefer not to tackle multiprocessing.
I’ll look into “cascading” my main app with OpenGL I/O application and send data to be displayed to separate OpenGL application.

It won’t close the window, but the window won’t be redrawn unless the event loop is running.

So long as the window is open, you need to process any events relating to it; particularly expose/paint events.

I am experiencing it differently, the window is simply gone.
Perhaps stopping it from being redraw is necessary first.
But how?

Check out the MainLoop- and window-close-related docs for your specific GLUT implementation.

For instance, in FreeGLUT docs…:

void glutSetOption ( GLenum eWhat, int value );

Description

Stores the value into a state variable named by eWhat.

The following state variables can be set:

GLUT_ACTION_ON_WINDOW_CLOSE - Controls what happens when a window is closed by the user or system.

  • GLUT_ACTION_EXIT will immediately exit the application (default, GLUT’s behavior).
  • GLUT_ACTION_GLUTMAINLOOP_RETURNS will immediately return from the main loop.
  • GLUT_ACTION_CONTINUE_EXECUTION will contine execution of remaining windows.

5. Event Processing Functions

In GLUT, control never returned from the event loop (as invoked by the glutMainLoop function) to the calling function. This prevented an application from having re-entrant code, in which GLUT could be invoked from within a callback, and it prevented the application from doing any post-processing (such as freeing allocated memory) after GLUT had closed down.

freeglut allows the application programmer to specify more direct control over the event loop by means of two new functions. The first, glutMainLoopEvent, processes a single iteration of the event loop and allows the application to use a different event loop controller or to contain re-entrant code. The second, glutLeaveMainLoop, causes the event loop to exit nicely; this is preferable to the application’s calling exit from within a GLUT callback.

Appreciate all comments.
Obviously I cannot have full knowledge of what are my options
after struggling with the main OpenGL concept for about two weeks.
It seems that the OpenGL graphical features are being hidden by all these “wrappers” and one has to have some experience with them.
The doc comments about glutLeaveMainLoop "to exit the event loop " - yes it does, but KILLS the window. I cannot call that “nice”.
However, I have the skeleton of my usage of OpenGL running, thanks to the support from this group.
Appreciate that very much.

You’re not using a wrapper around OpenGL. You’re just using FreeGLUT; all it does is create and maintain an OpenGL window for you, communicating with your application at various points. It doesn’t make any actual OpenGL calls.

Why not? If you’re using FreeGLUT’s main loop directly, the only reason to exit the main loop is to terminate that window.

And if you’re just polling FreeGLUT’s main loop with glutMainLoopEvent, then you shouldn’t be calling glutLeaveMainLoop at all.

Just for sake of discussion.
Let’s clarify - the “tool” is OpenGL
the "implementation " is a © library , actually few of them, including freeGLUT.
I may not been clear WHY I am using OpenGL , so I will try to clarify that omission.
My task is to display processed data, ASYNCHRONOUSLY.
OpenGL does reasonable job displaying such data, xGLUT does the asynchronous connection - implemented by "main (event ) loop " and “idle callback function”.
Works as expected, irregardless if correct terminology is used or not.

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