Thread: function pointers in openGL

  1. #1
    tall guy
    Join Date
    Aug 2005
    Location
    in bed
    Posts
    4

    function pointers in openGL

    Hello.
    I'm trying to use openGL extension functions in a way that will compile on multiple platforms, hence I am using freeglut's glutGetProcAddress function. However, when I have code like the following:
    Code:
    void (*glConvolutionFilter2D)(GLenum target,
      GLenum internalformat,  GLsizei width,
      GLsizei height,  GLenum format,
      GLenum type,  const GLvoid *image) __attribute__((cdecl));
    glConvolutionFilter2D = glutGetProcAddress("glConvolutionFilter2D");
    The last line generates the compile error:
    invalid conversion from ‘void*’ to ‘void (*)(GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid*)'
    I have had a look at function-pointers.org and this is what it suggests.
    What am I doing wrong?

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    glutGetProcAddress() doesn't work that way.

    In your glext.h header, there are definitions and API entrys for all of the GL extensions. the APIENTRY def for glConvolutionFilter2d() is PFNGLCONVOLUTIONFILTER2DPROC. You then use this data type to return the proc address with glutGetProcAddress().

    Code:
    PFNGLCONVOLUTIONFILTER2DPROC glConvolutionFilter2D;
    
    void setupGLExtensions()
    {
      glConvolutionFilter2D=  (PFNGLCONVOLUTIONFILTER2DPROC) glutGetProcAddress("glConvolutionFilter2D");
    }
    If you want it explained better, just let me know.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  3. #3
    tall guy
    Join Date
    Aug 2005
    Location
    in bed
    Posts
    4

    Thumbs up

    Thanks for that, it compiles now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Class function pointers
    By VirtualAce in forum C++ Programming
    Replies: 40
    Last Post: 02-17-2005, 12:55 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM