OpenGL on ATI/Linux

Hi,

I was wondering if people have tried using ATI extensions on Linux.

If yes, then what headers did you use? Do you have access to any working examples for vertex/pixel shading/pbuffers on ATI cards?

I would appreciate your help.

Thanks,
Manpreet.

I was wondering if people have tried using ATI extensions on Linux.

WEll, I’ve used OpenGL extensions under Linux, but not ATI specific extensions. But it’s all the same thing, really, unless you’re talking about a specific quirk with an ATI extension?

If yes, then what headers did you use?

GL/gl.h and GL/glext.h

Do you have access to any working examples for vertex/pixel shading/pbuffers on ATI cards?

… no… I have code whcih uses extensions wrapped up in my own proejct, though. I have written my own wrapper to load extensions which works for me. Is your question one of “how do I use opengl extensions under linux”, or “how do I use pixelshaders”? I can send you my glextension wrapper, if you’d like. It’s not exciting, it just binds function pointers. If your question was on how to use a specific extension, then you hsould post a question regarding that.

FYI, here is my extension loader thing.

It… works for me, but I suspect it is suboptimal and maybe has redundant stuff. <shrugs> What follows is three files: the gl_ext.h header which makes the function pointers and gl_ext.c that binds them. The file gl_ext_prototypes.h is the list of extensions that I am particularly interested in – this includes all the extensions my project needs in a magic table defined by #defines that says what the name of an extension is, what it depends on, and what function ptr is assigned to it.

For example, if a new opengl extension, glXFooBar, was released, then I might add the line

INIT_GLX(glXFooBarExt, PFNGLXFOOBAREXTPROC,
“GLX_EXT_FOOBAR”, “glXFooBar”)

… which says that the function ptr is glXFooBarExt (so I can call it with glXFooBarExt(…)). The function cast is defined in the extneion, and its cast is PFNGLXyadayadayada. The extension string in the regsistry is GLX_EXT_FOOBAR, and the name if the function for lookup is “glXFooBar”.

I hope this helps
cheers,
John

/* gl_ext.h ---------------------------- */

#ifndef __INCLUDED_GL_EXTENSION_HOOKS
#define __INCLUDED_GL_EXTENSION_HOOKS
 
/* opengl 1.4 extension hooks */
 
#include<GL/glext.h>
 
#ifdef __cplusplus
extern "C" {
#endif
 
  /* construct the function hooks */
#define INIT_GLEXT(fp, ft, ign1, ign2) extern ft fp;
#include"gl_ext_prototypes.h"
#undef INIT_GLEXT
 
  int registerOpenGLextensions(void);
  int checkOpenGLExtensionRequirements(char *);
 
#ifdef GLX_MISSING_FUNCTIONALITY_WARNING
#warning "note: missing extensions _may not_ be a problem; don't panic yet =)"
#undef GLX_MISSING_FUNCTIONALITY_WARNING
#endif
 
#ifdef __cplusplus
}
#endif
 
#endif

/* gl_ext.c ---------------------------- */

#include<assert.h>
#include<stdio.h>
#include<string.h>
                                                                                
#include<GL/glx.h>
#include<GL/glext.h>
                                                                                
#include"gl_ext.h"
                                                                                
/* the list of extension hooks */
#define INIT_GLEXT(fp, ft, ign1, ign2) ft fp=(ft)NULL;
#include"gl_ext_prototypes.h"
#undef INIT_GLEXT
                                                                                
/* list of functions to initialise the extension functions */
typedef struct {
  void **functionptr;
  char extension_string[64];
  char prototype_string[64];
} INIT_OPENGL_EXTENSIONS;
                                                                                
int registerOpenGLextensions(void)
{
  /* construct the list of opengl functions to initialise */
  const INIT_OPENGL_EXTENSIONS glextlist[]={
#define INIT_GLEXT(f, ign1, e, p) \
    { (void**)(&f), e, p },
#include"gl_ext_prototypes.h"
    { NULL, "", "" }                                /* terminating sentinel */
#undef INIT_GLEXT
  };
                                                                                
  int t;
  char *extstr=(char*)glGetString(GL_EXTENSIONS);
  int ok=1;
                                                                                
  for(t=0; glextlist[t].functionptr!=NULL; t++) {
    if(strstr(extstr, glextlist[t].extension_string)==0) {
      /* failing may not be bad if the functionality isn't actually used, so
         this "error handling" should be re-examined */
      fprintf(stderr, "ack!fatal: unable to initialise %s
",
              glextlist[t].extension_string);
      ok=0;
    } else {
      *(glextlist[t].functionptr)=
        glXGetProcAddressARB((GLubyte*)glextlist[t].prototype_string);
      ok=ok&(*(glextlist[t].functionptr)!=NULL);
#ifdef __DEBUG_EXTENSION_LOADING
      fprintf(stderr, "loading extension %s (%p)
",
             (GLubyte*)glextlist[t].prototype_string,
              *(glextlist[t].functionptr));
#endif
    }
  }
  return(ok);
}
 
/* checks to see if a space-deliminated set of opengl extension strings
   are supported in the graphics context.  It returns 1 if all extensions
   are supported and 0 if at least one extension is missing.  It modifies
   the input string to indicate which extensions are not supported */
int checkOpenGLExtensionRequirements(char *str)
{
  char *extstr=(char*)glGetString(GL_EXTENSIONS);
  char *cpy=(char*)malloc(strlen(str));
  int lastp=0, curr;
 
  assert(cpy);
  cpy[0]=0;
 
  while(str[lastp]!=0) {
    /* read token step */
    for(curr=lastp;!isspace(str[curr]) && str[curr]!=0; curr++);
 
    /* process token step */
    str[curr++]=0;
    if(strstr(extstr, str+lastp)==0) {
      /* not found */
      if(cpy[0]!=0)
        strcat(cpy, ";");
      strcat(cpy, str+lastp);
    }
 
    /* skip whitespace step */
    for(;isspace(str[curr])&&str[curr]!=0; curr++);
    lastp=curr;
  }
 
  strcpy(str, cpy);
  free(cpy);
 
  return(str[0]==0);
}

/* gl_ext_prototypes.h ---------------------------- */

#include<GL/glx.h>
#include<GL/glext.h>
                                                                                
#ifdef GLX_MISSING_FUNCTIONALITY_WARNING
#undef GLX_MISSING_FUNCTIONALITY_WARNING
#endif
                                                                                
/* this structure is a list of preprocessor macros to pack _all_ the relevent
   info for an opengl extension into one place.  gl_ext.h/c #include's this
   file a lot with different INIT_GLEXT defs */
                                                                                
/* equivilent string is GL_ARB_window_pos, but this doesn't seem to be
   #def'ed in my copy of glext.h */
                                                                                
#if 1
#ifdef GL_ARB_window_pos
INIT_GLEXT(glWindowPos2fARB, PFNGLWINDOWPOS2FARBPROC,
           "GL_ARB_window_pos", "glWindowPos2fARB")
#else
#warning "GL_ARB_window_pos not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#endif
                                                                                
#if 1
#ifdef GL_ARB_transpose_matrix
INIT_GLEXT(glLoadTransposeMatrixdARB, PFNGLLOADTRANSPOSEMATRIXDARBPROC,
           "GL_ARB_transpose_matrix", "glLoadTransposeMatrixdARB")
INIT_GLEXT(glMultTransposeMatrixdARB, PFNGLMULTTRANSPOSEMATRIXDARBPROC,
           "GL_ARB_transpose_matrix", "glMultTransposeMatrixdARB")
#else
#warning "GL_ARB_transpose_matrix not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
                                                                                
#endif
                                                                                
#if 1
#ifdef GL_ARB_multitexture
INIT_GLEXT(glActiveTextureARB, PFNGLACTIVETEXTUREARBPROC,
           "GL_ARB_multitexture", "glActiveTextureARB")
INIT_GLEXT(glClientActiveTextureARB, PFNGLCLIENTACTIVETEXTUREARBPROC,
           "GL_ARB_multitexture", "glClientActiveTextureARB")
INIT_GLEXT(glMultiTexCoord2fARB, PFNGLMULTITEXCOORD2FARBPROC,
           "GL_ARB_multitexture", "glMultiTexCoord2fARB")
INIT_GLEXT(glMultiTexCoord2fvARB, PFNGLMULTITEXCOORD2FVARBPROC,
           "GL_ARB_multitexture", "glMultiTexCoord2fvARB")
INIT_GLEXT(glMultiTexCoord3fARB, PFNGLMULTITEXCOORD3FARBPROC,
           "GL_ARB_multitexture", "glMultiTexCoord3fARB")
INIT_GLEXT(glMultiTexCoord3fvARB, PFNGLMULTITEXCOORD3FVARBPROC,
           "GL_ARB_multitexture", "glMultiTexCoord3fvARB")
#else
#warning "GL_ARB_multitexture not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#endif
 
#if 1
#ifdef GL_EXT_blend_minmax
INIT_GLEXT(glBlendEquationEXT, PFNGLBLENDEQUATIONEXTPROC,
           "GL_EXT_blend_minmax", "glBlendEquationEXT")
#else
#warning "GL_ARB_blend_minmax not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#endif
 
#if 1
#ifdef GL_EXT_blend_func_separate
INIT_GLEXT(glBlendFuncSeparateEXT, PFNGLBLENDFUNCSEPARATEEXTPROC,
           "GL_EXT_blend_func_separate", "glBlendFuncSeparateEXT")
#else
#warning "GL_ARB_blend_minmax not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#endif
 
#if 0
 
#ifdef GLX_SGIX_pbuffer
#ifdef GLX_VERSION_1_3
INIT_GLEXT(glXCreateGLXPbufferSGIX, PFNGLXCREATEGLXPBUFFERSGIXPROC,
           "GLX_SGIX_pbuffer", "glXCreateGLXPbufferSGIX")
INIT_GLEXT(glXDestroyGLXPbufferSGIX, PFNGLXDESTROYGLXPBUFFERSGIXPROC,
           "GLX_SGIX_pbuffer", "glXDestroyGLXPbufferSGIX")
INIT_GLEXT(glXQueryGLXPbufferSGIX, PFNGLXQUERYGLXPBUFFERSGIXPROC,
           "GLX_SGIX_pbuffer", "glXQueryGLXPbufferSGIX")
INIT_GLEXT(glXSelectEventSGIX, PFNGLXSELECTEVENTSGIXPROC, "GLX_SGIX_pbuffer",
           "glXSelectEventSGIX")
INIT_GLEXT(glXGetSelectedEventSGIX, PFNGLXGETSELECTEDEVENTSGIXPROC,
           "GLX_SGIX_pbuffer", "glXGetSelectedEventSGIX")
#else
#warning "GLX_SGIX_pbuffer not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#warning "GLX_SGIX_pbuffer not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
 
#ifdef GLX_SGIX_fbconfig
#ifdef GLX_VERSION_1_3
INIT_GLX(glXGetFBConfigAttribSGIX, PFNGLXGETFBCONFIGATTRIBSGIXPROC,
         "GLX_SGIX_fbconfig", "glXGetFBConfigAttribSGIX")
INIT_GLX(glXChooseFBConfigSGIX, PFNGLXCHOOSEFBCONFIGSGIXPROC,
         "GLX_SGIX_fbconfig", "glXChooseFBConfigSGIX")
INIT_GLX(glXCreateGLXPixmapWithConfigSGIX,
         PFNGLXCREATEGLXPIXMAPWITHCONFIGSGIXPROC, "GLX_SGIX_fbconfig",
         "glXCreateGLXPixmapWithConfigSGIX")
INIT_GLX(glXCreateContextWithConfigSGIX, PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC,
         "GLX_SGIX_fbconfig", "glXCreateContextWithConfigSGIX")
INIT_GLX(glXGetVisualFromFBConfigSGIX, PFNGLXGETVISUALFROMFBCONFIGSGIXPROC,
         "GLX_SGIX_fbconfig", "glXGetVisualFromFBConfigSGIX")
INIT_GLX(glXGetFBConfigFromVisualSGIX, PFNGLXGETFBCONFIGFROMVISUALSGIXPROC,
         "GLX_SGIX_fbconfig", "glXGetFBConfigFromVisualSGIX")
#else
#warning "GLX_SGIX_fbconfig not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
#else
#warning "GLX_SGIX_fbconfig not found"
#define GLX_MISSING_FUNCTIONALITY_WARNING
#endif
 
#endif

Thanks John.

I appreciate your help.

I also found another useful tool. There is a library called ‘glew’ that does the wrapping stuff for you.
You just need to call glewInit in your main and link to libglew.so. glew.sf.net.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.