GLvoid or void ...

Started by
5 comments, last by benjamin bunny 19 years, 7 months ago
is there any significant difference between using either of these? also why do i see GLvoid declared in some function parameters in opengl programs? I am confused about some of this syntax ... ie ... GLvoid glInit (GLvoid) ... instead of void glInit () I really don't understand why, i can take out GLvoid declared as parameters and replace all GLvoid types with void and my progarm works exactly the same. why use GLvoid? and why declare it in a functions parameter?
Advertisement
They're the same. OpenGL uses various typedefs with a "GL" prefix in order ensure that the correct type is used for function parameters and return types; since types are not necessarily the same on all platforms. For example, GLfloat is identical to using float on most systems, and GLdouble is the equivalent to double. If you're developing for many platforms, it's a good idea to use the GL types (although in the case of void, it won't make any difference). Otherwise you can happily ignore them.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Related, in something that is supposed to be portable, I have a cloth, which from OpenGL's point of view is a non-closed mesh.

When this is deformed the positions of the vertices move as part of the simulation. If I use GLfloat for the vertices, I can potentially avoid a copy operation. On the other hand, if the physics code needs the data (and it probably would) then it would have to deal with GLfloats, which is a little awkward if you are trying for API independence. (Physics should work without gl.h anyway!) I'm not entirely sure that keeping data in an API specified format is good for this anyway.

If you are using OpenGL, how useful is the ability to rewrite the renderer for Direct3D? Should I ignore API independence and code just for OpenGL? (After all, OpenGL itself is platform independent!)

-- Jonathan
In early C language there was no such thing like 'void' at all (that's why when you omit return type of function, it will default to int). I just looked up in '88 K&R (had to be careful to not tear the old, yellowish paper apart :) ) and void is only mentioned there as reserved word used in some compilers. So void was effectively an extension to the standard language these days. Perhaps at the time when GL 1.0 was being defined (was it '92 ?), the compilers that didn't support void were still widely in use. For such compiler, the GLvoid had to be typedef-ined as int in the <GL.h>, I guess.
"Dawn is a tramp." Dusk.
As have already been mentioned, these are issues related to platform-independence, and C. In the case of void as a function-parameter, in C there's a difference between specifying that a function takes a void parameter and having an empty parameter specification.
Example:
void myFunction1(void);
void myFunction2();

In C, you were not allowed to pass parameters when calling myFunction1, but you are allowed to pass any number of parameters when calling myFunction2. In modern C, and in C++ both functions act as if they were declared as myFunction1 is.

- Neophyte
Could be the GL prefix related to allocating variables in the video memory ?[looksaround]
Quote:Original post by Daos
Could be the GL prefix related to allocating variables in the video memory ?[looksaround]


No.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement