supagu
January 9, 2006, 12:01am
1
trying to port my engine from win32 to linux and seems it doesnt like my extension loading code:
header:
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
source:
#include <GL/glext.h>
if ( ExtensionSupported("GL_ARB_point_parameters") )
{
glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)
activeWindow->GetExtensionAddress("glPointParameterfARB");
glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)
activeWindow->GetExtensionAddress("glPointParameterfvARB");
Log::Print("Point Sprites [OK]
");
}
:
:
void* Window::GetExtensionAddress(const char* extension)
{
return (void*)glXGetProcAddress((const GLubyte*)extension);
}
and i get the following error:
Device.cpp:195: error: assignment of function 'void glPointParameterfARB(GLenum, GLfloat)'
Device.cpp:195: error: cannot convert 'void (*)(GLenum, GLfloat)' to 'void ()(GLenum, GLfloat)' in assignment
i get a bunch of errors all the same with the
cannot convert:
blah (*) blah to blah () blah
any ideas?
first of all, it’s not a good idea to create a “Window” class, because “Window” is defined in X.h .
i’ve modified your code:
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glext.h>
class Win {
public: Win() {};
~Win() {};
void *GetExtensionAddress(const char *); };
Win *activeWindow;
PFNGLPOINTPARAMETERFARBPROC my_glPointParameterfARB;
PFNGLPOINTPARAMETERFVARBPROC my_glPointParameterfvARB;
void GetProcAddresses() {
my_glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC) activeWindow->GetExtensionAddress("glPointParameterfARB");
my_glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC) activeWindow->GetExtensionAddress("glPointParameterfvARB"); }
void* Win::GetExtensionAddress(const char* extension) {
return (void*)glXGetProcAddressARB((const GLubyte*)extension); }
the problem seems to be that glPointParameterfARB and glPointParameterfvARB are already defined in glext.h, but not as pointers to functions, but as the functions themselves. so, what your code tries to do is similar to
int i;
i = new int;
to solve the problem, you can define your own function pointers (my_glPointParameterfARB and my_glPointParameterfvARB) and work with them.
supagu
January 9, 2006, 2:23am
3
oh i use my own namespace so i can get away with calling my window a window.
okay so if glext has defined the function already does this mean i can use it with out having to set up the function pointer manually?
ive managed to get things compiling with:
#define LoadGLExtension(f) \
{ \
if (f == NULL) \
{ \
void **p = reinterpret_cast<void**>(&f); \
*p = activeWindow->GetExtensionAddress(#f); \
} \
}
eg:
LoadGLExtension(glPointParameterfARB);
which seems to be working untill i go to use one of the extensions then a segmentation fault (they may or may not be related, not sure).
system
January 9, 2006, 12:19pm
5
well, i tried it, it seems the functions already have an address, but when i go to use the extension i get a segmentation fault.
if i remove the null check and forece the function pointer to a new address, it crashes trying to assign the pointer with a segmentation fault
:-/
so you still get a segmentation fault- are you sure that you have made a valid GL context current?
here’s a minimum code that uses the glPointParameter extension. maybe you want to compile it and try it.
#include <stdio.h>
#include <stdlib.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glext.h>
Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
GLint att[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 24, None};
XVisualInfo *vi = glXChooseVisual(dpy, 0, att);
GLXContext glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
Visual *vis = vi->visual;
Colormap cmap = XCreateColormap(dpy, root, vis, AllocNone);
int dep = DefaultDepth(dpy, 0);
int cmask = CWColormap | CWBorderPixel | CWEventMask | CWOverrideRedirect;
int emask = ExposureMask | KeyPressMask | KeyReleaseMask;
XEvent xev;
XSetWindowAttributes swa;
Window win;
void Redraw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glXSwapBuffers(dpy, win); }
int main(int argc, char *argv[]) {
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = emask;
swa.override_redirect = false;
win = XCreateWindow(dpy, root, 0, 0, 800, 600, 0, dep, InputOutput, vis, cmask, &swa);
XMapWindow(dpy, win);
glXMakeCurrent(dpy, win, glc);
glClearColor(0., 0., 1., 1.);
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0);
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, 1.0);
while(true) {
XNextEvent(dpy, &xev);
if(xev.type == Expose) {
Redraw(); }
else if(xev.type == KeyPress) {
glXMakeCurrent(dpy, None, NULL);
glXDestroyContext(dpy, glc);
exit(0); } } }
//
// gcc -o ext2 ext2.cc -lX11 -lGL -lGLU
//
supagu
January 10, 2006, 12:29am
7
yeah that works, seems i dont have to set up any extensions at all on linux
cheers
songho
January 12, 2006, 11:12am
9
Just confirm that ATI card (fglrx driver) also works without a special setup.
I have tested loading GL extensions on my SuSE and it works without glXGetProcAddressARB() to get the pointer to function.
I only added this before including glext.h:
#define GL_GLEXT_PROTOTYPES
==song==