C++ – How to initialize glut with fake parameters

cglewglutopengl

I'm using opengl, using the GLUT and GLEW libraries to create a plugin for a certain application.

This plugin doesn't start with a simple int main(argc, argv). So i can't pass these values to glutInit().

I tried something like this:

glutInit(0, NULL); <--- Crash
GLenum err = glewInit();

But i crashed when it tried to call the glutInit() function. Can i reconstruct those params some how, so that it won't crash and still be able to use the Glut library..??

Best Answer

You can do it like this :

#include <GL/freeglut.h>

int main()
{
  char fakeParam[] = "fake";
  char *fakeargv[] = { fakeParam, NULL };
  int fakeargc = 1;

  glutInit( &fakeargc, fakeargv );

  //...
}

but take a note that it is an ugly hack.