Reputation: 26772
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..??
Upvotes: 4
Views: 5463
Reputation: 5213
I propose this as a de-facto standard for initializing glut applications.
static inline void glutInstall()
{
char *glut_argv[] = {
"",
(char *)0
};
int glut_argc = 0;
glutInit(&my_argc, my_argv);
}
This function can be modified on per-application basis to provide glut with the arguments it needs(if any), while permanently solving the issue of everyone asking why you are passing command line arguments to a 3rd party library.
Upvotes: 0
Reputation: 1259
Note the following code from the source (freeglut_init.c:677
):
void FGAPIENTRY glutInit( int* pargc, char** argv )
{
char* displayName = NULL;
char* geometry = NULL;
int i, j, argc = *pargc;
...
(Note the dereferencing.)
It seems that glutInit()
does require a minimum of the process name, although the man page doesn't shed any light on this.
Upvotes: 3
Reputation: 409186
You might have to call glutInit
with a valid argv
parameter, even if you don't have any:
char *my_argv[] = { "myprogram", NULL };
int my_argc = 1;
glutInit(&my_argc, my_argv);
It might also be that the first parameter is a pointer to an int
, and it can't be NULL? Then it might be enough to only pass a valid argc
parameter:
int my_argc = 0;
glutInit(&my_argc, NULL);
Upvotes: 4
Reputation: 64223
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.
Upvotes: 7