0

I've been trying to use freeglut in a Qt project. Unfortunately when I use some glut function like 'glutWireSphere' or 'glutWireTorus' I get an error:

freeglut ERROR: Function called without first calling 'glutInit'.

And when I try to run an application it immediately quits itself. I don't know where exactly should I call 'glutInit'. I've installed freeglut according to this tutorial:

https://www.youtube.com/watch?v=M4fm-cHGoYU&index=1&list=LLkYBBRyDu3gfOojsRQOM3JQ
user30935
  • 51
  • 1
  • 8

1 Answers1

3

I've figured it out. It was quite simple actualy. I needed to use 'glutInit( & argc, argv )' in my main.cpp like this:

int main(int argc, char *argv[])
{
    glutInit( & argc, argv );
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
user30935
  • 51
  • 1
  • 8
  • You should not mix GLUT with Qt. There are only 4 meshes offered by GLUT, and except for the teapot, neither is difficult to implement independently from GLUT (and the teapot isn't that hard either). – datenwolf Nov 01 '14 at 01:46
  • Oh, ok then. Thanks for advice! BTW do you know what could happen if I'd mix GLUT with Qt? What kind of problems could it cause? I'm kinda curious now. – user30935 Nov 01 '14 at 02:57
  • @user30945: Well, like you already found out, some GLUT functions may depend on GLUT being initialized. When initializing a GLUT implementation may (but doesn't have to) install a number of things in the process that affect the later creation of Windows and the execution of the event loop. After all, GLUT is built on the premise that `glutMainLoop()` never returns, i.e. doesn't have to play well with others. And then of course, should you call `glutMainLoop()` the rest of your program (using Qt) will cease to work, because no Qt events get processed anymore. – datenwolf Nov 01 '14 at 11:12