Sign in to follow this  
Lord_Vader

How to use an extension directly????????

Recommended Posts

Lord_Vader    125
It has occured to me the following problem. The extension GL_EXT_point_parameters is supported by my system.But when I keep the return address of wglGetProcAddress("glPointParameterEXT")at a global scope variable,I take compliler errors like this: missing type specifier - int assumed. Note: C++ does not support default-int glPointParameterEXT' : redefinition; different type modifiers initializing' : cannot convert from 'PFNGLPOINTPARAMETERFEXTPROC' to 'int I have made it work but only when I return the address within a function. like void FunctionName() { glPointParameterEXT = (PFNGLPOINTPARAMETERFEXTPROC) wglGetProcAddress("glPointParameterEXT"); } so, how can I use the extension functions directly?

Share this post


Link to post
Share on other sites
b2b3    602
How do you define your glPointParameterEXT at global scope? This always works for me:

// in header file that is included when I need extension:
extern PFNGLPOINTPARAMETERFEXTPROC glPointParameterEXT;

// in cpp file where I initialize function pointers:
PFNGLPOINTPARAMETERFEXTPROC glPointParameterEXT = NULL;

and then I can use it just like any other pointer to function.

Share this post


Link to post
Share on other sites
tj963    234
Like b2b3 alluded to, you just need to define your variable.

PFNGLPOINTPARAMETERFEXTPROC glPointParameterEXT =
(PFNGLPOINTPARAMETERFEXTPROC)wglGetProcAddress("glPointParameterEXT");

tj963

Share this post


Link to post
Share on other sites
Lord_Vader    125
I define it like this

In header file:

typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);

In cpp file:

PFNGLPOINTPARAMETERFEXTPROC glPointParameterEXT;

glPointParameterEXT = (PFNGLPOINTPARAMETERFEXTPROC) wglGetProcAddress("glPointParameterEXT");

but anything I do at a global scope
produces the errors

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

glPointParameterEXT' : redefinition; different type modifiers

see declaration of 'glPointParameterEXT'

error C2440: 'initializing' : cannot convert from 'PFNGLPOINTPARAMETERFEXTPROC' to 'int'

Share this post


Link to post
Share on other sites
paul_nicholls    167
Quote:
Original post by Lord_Vader
It has occured to me the following problem.

The extension GL_EXT_point_parameters is supported by my system.But when I keep the return address of wglGetProcAddress("glPointParameterEXT")at a global scope variable,I take compliler errors like this:

missing type specifier - int assumed. Note: C++ does not support default-int

glPointParameterEXT' : redefinition; different type modifiers

initializing' : cannot convert from 'PFNGLPOINTPARAMETERFEXTPROC' to 'int

I have made it work but only when I return the address within a function.

like
void FunctionName()
{
glPointParameterEXT = (PFNGLPOINTPARAMETERFEXTPROC) wglGetProcAddress("glPointParameterEXT");
}

so, how can I use the extension functions directly?


For extensions under OpenGL I use GLExt.pas that comes with the pascal version of SDL.

I haven't had any issues :)

perhaps there is something similar when using C/C++?

cheers,
Paul.

Share this post


Link to post
Share on other sites
b2b3    602
Quote:
Original post by paul_nicholls
For extensions under OpenGL I use GLExt.pas that comes with the pascal version of SDL.

I haven't had any issues :)

perhaps there is something similar when using C/C++?

cheers,
Paul.


Sure there is. It's glext.h. It contains all declarations and typedefs for all extensions you need.

To OP:
As Solias suggested, you should use GLEE or similar extension loader. It's quite easy to use and it will save you all the trouble of detecting which extensions are supported and it will initialize appropriate pointers for you.

Also, if you want to use variable from one cpp file in another, you have to use extern. If you don't, compiler will assume, that your function returns int and that generates an error. You can put it into the header file if you want (as I do in example in my first post).

Share this post


Link to post
Share on other sites
Ezbez    1164
Yeah, there's Glext for C/C++, but I prefer what the first reply said, using GLee. It's very very simple to use.

Share this post


Link to post
Share on other sites
Lord_Vader    125
The point is that EVEN if I use the extern the same errors occurs.

I am aware of GLEE but I would like to know how I can fix this first...

As I told you before I manage to use the extension within a function...
The problem is why I cant use it at global scope...

Share this post


Link to post
Share on other sites
Digitalfragment    1504
the error you are getting

initializing' : cannot convert from 'PFNGLPOINTPARAMETERFEXTPROC' to 'int

is because PFNGLPOINTPARAMETERFEXTPROC hasnt been defined yet. you need to include glext.h which has the typedef PFNGLPOINTPARAMETERFEXTPROC defined prior to trying to declare or extern it. otherwise the compiler doesnt know what on earth that function is.

Share this post


Link to post
Share on other sites
Lord_Vader    125
And I say, Isn't that definition quite enough to make the compiler understand what on earth is going on?

typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You can't assign to a global variable in this way with C++ (that is, by first declaring it, and then assigning to it). What's more you cannot assign the result of a function call to a global variable (you may only assign a constant, more or less). This is simply the way it works in C++. So, instead declare it, and then assign to it within a function, as you mentioned previously does in fact work.

As a side note, essentially the reason that you are getting the error you're getting is that in C, not declaring a type of a function would default to an integer. I think what is happening is that the compiler is thinking that you are trying to define such a function, and errors out before getting to the "real" error: that you can't assign the result of a runtime evaluation to a global.

Hope that helps.
-zRX

Share this post


Link to post
Share on other sites
Lord_Vader    125
Ohhhhhhhhhhhhhhhhh you were right(at least at the first point)

the right way is to define the variable(in this case wglSwapIntervalEXT for example) at the time u declare it ,if it is global:

PFNWGLEXTSWAPCONTROLPROC wglSwapIntervalEXT = (PFNWGLEXTSWAPCONTROLPROC) wglGetProcAddress("wglSwapIntervalEXT");

that way it worked.


I was confused by the following link:

Take a look at the link:

http://www.opengl.org/resources/features/OGLextensions/

At one point it says:

First, declare function prototype typedefs that match the extension’s entry points. For example:


#ifdef _WIN32
typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname, GLfloat param);
typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname, const GLfloat *params);
#endif

Your <GL/gl.h> header file may already have these typedefs declared if your <GL/gl.h> defines
the GL_EXT_point_parameters macro. Now declare global variables of the type of these
function prototype typedefs like this:

#ifdef _WIN32
PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT; //???????????????
PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT; //???????????????
#endif

The names above exactly match the extension’s function names. Once we
use wglGetProcAddress to assign these function variables the address of the OpenGL
driver’s extension functions, we can call glPointParameterfEXT and glPointParameterfvEXT
as if they were normal functions. You pass wglGetProcAddress the name of the routine as
an ASCII string. Verify that the extension is supported and, if so, initialize the function variables
like this:

int hasPointParams = isExtensionSupported("GL_EXT_point_parameters");

#ifdef _WIN32
if (hasPointParams) {
glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
wglGetProcAddress("glPointParameterfEXT");
glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
wglGetProcAddress("glPointParameterfvEXT");
}
#endif

Note that before the code above is called, you should have a current OpenGL rendering context.

With the function variables properly initialized to the extension entry-points, you can
use the extension like this:

if (hasPointParams) {
static GLfloat quadratic[3] = { 0.25, 0.0, 1/60.0 };
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
glPointParameterfEXT(GL_POINT_FADE_THRESHOLD_SIZE_EXT, 1.0);
}

Be careful because the function returned by wglGetProcAddress is only be guaranteed to
work for the OpenGL rendering context that was current when wglGetProcAddress was called.
If you have multiple contexts that return different extension function addresses, keeping the
function addresses in global variables as shown above may create problems. You may need to
maintain distinct function addresses on a per-context basis.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this