Hi,
I have an OpenGL program that uses an OpenCV function call to calculate the coordinates relative to some markers. Once that is done OpenGL should then open a window and display some graphic (e.g. point (5px)) at the coordinates calculated by the OpenCV function. The problem I have is that the cvCaptureFromCAM(CV_CAP_ANY); function causes the program to terminate with the following error:
GLUT Fatal Error: redisplay needed for window 1, but no display callback.
If I comment it out, then it runs (but no webcam frames ofcorse).
The OpenGL and OpenCV functions run OK as separate programs. I’m not sure what the problem could be. Would appreciate any pointers you may have.
Here’s the code (excluding header files etc)
void setup(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glPointSize(10);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex2f(mid, 50);
glEnd();
glFlush();
}
void resize(int width, int height)
{
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void capture(void) //OpenCV function
{
CvCapture* capture = 0;
IplImage* frame = 0;
capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture)
{
printf("Could not initialise capturing...
");
}
frame = cvQueryFrame(capture);
...
}
int main(int argc, char **argv)
{
// Initialize GLUT.
glutInit(&argc, argv);
// Set display mode as single-buffered and RGB color.
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// Set OpenGL window size.
glutInitWindowSize(500, 500);
// Set position of OpenGL window upper-left corner.
glutInitWindowPosition(100, 100);
// Create OpenGL window with title.
glutCreateWindow("Lumbar Tracking");
// Initialize.
setup();
capture();
// Register display routine.
glutDisplayFunc(display);
// Register reshape routine.
glutReshapeFunc(resize);
// Begin processing.
glutMainLoop();
return 0;
}