AddingOpenGLExtensions

From TDN

Contents

Adding OpenGL Extensions to TGE

Introduction

OpenGL extensions are an integral part of how OpenGL supports new technology. Adding extensions to Torque can be confusing at first, however this will walk you through adding support for the extension EXT_blend_color.

The first thing to do is look up the extension you want to support. A great page that I found to do this is: http://www.msi.unilim.fr/~porquet/glexts/index.html

I am sure there are many others, this was the one I stumbled across and it is very well formatted.

The page for EXT_blend_color is here, just in case you want to follow along: http://www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_color.txt.html

Step 1

The first step is to get the #define’s you need to add for this extension. They can be found in the “New Tokens” section. Go to platform/GLExtFunc.h and add these:

/* EXT_blend_color */
// http://www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_color.txt.html
#define GL_CONSTANT_COLOR_EXT                0x8001
#define GL_ONE_MINUS_CONSTANT_COLOR_EXT      0x8002
#define GL_CONSTANT_ALPHA_EXT                0x8003
#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT      0x8004
#define GL_BLEND_COLOR_EXT                   0x8005

GL_GROUP_BEGIN(EXT_blend_color)
GL_FUNCTION(void,       glBlendColorEXT, (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha), return; )
GL_GROUP_END()

You also see I added the function here. You can get the function prototype on the page from the section ‘New Procedures and Functions’.


Win32 Specific

Now is where it gets a little hairy and platform-specific. I only did Windows (since it’s the only one I’ve tested this on, but it should work on the others, man how many times have you heard that) You should be able to add support to Mac and Linux very easily once you get the idea.

What this next chunk of code will do is search the extension support string for the extension we are adding. You can find the name string for the extension on the description for it, under the section “Name Strings”.

In platformWin32/winGL.cc near the top there is an enum with extensions in it that looks like this

//GL_EXT/ARB
enum {
   ARB_multitexture              = BIT(0),
   ARB_texture_compression       = BIT(1),
   ...

To the end, add the extension with the next free bit, in our case, it will look like this

//GL_EXT/ARB
enum {
   ARB_multitexture              = BIT(0),
   ARB_texture_compression       = BIT(1),
   EXT_compiled_vertex_array     = BIT(2),
   EXT_fog_coord                 = BIT(3),
   EXT_paletted_texture          = BIT(4),
   NV_vertex_array_range         = BIT(5),
   EXT_blend_color               = BIT(6)
};

In platformWin32/winGL.cc in the GL_EXT_Init function, add the following near the other ones that look like this

// EXT_blend_color
if(pExtString && dStrstr(pExtString, (const char*)"GL_EXT_blend_color") != NULL)
{
   extBitMask |= EXT_blend_color;
   gGLState.suppEXTblendcolor = true;
} else {
   gGLState.suppEXTblendcolor = false;
}

Then, down a bit lower, add the console printout, in our case add this

if (gGLState.suppEXTblendcolor)        Con::printf("  EXT_blend_color");

and

if (!gGLState.suppEXTblendcolor)      Con::warnf("  EXT_blend_color");

In platformWin32/winGLSpecial.cc add this somewhere, this is the function for the GL logging

static void APIENTRY logglBlendColorEXT(GLclampf red, GLclampf green, GLclampf blue, 
GLclampf alpha)
{
   fprintf( winState.log_fp, "glBlendColor( %f, %f, %f, %f )\n", red, green, blue, alpha );
   fflush(winState.log_fp);
   dllglBlendColorEXT(red, green, blue, alpha);
}

Next go to platformWin32/platformGL.h and add a bool to the GLstate struct for your new extension. I added:

bool suppEXTblendcolor;

You can also add an inline for getting support

inline bool dglDoesSupportEXTBlendColor()
{
   return gGLState.suppEXTblendcolor;
}

And that should do you! I will have to add this support to Mac and if I remember I will update this resource.

Conclusion

You will have to forgive me if I have forgotten something because I am writing this backwards, IE I already did it, now I have to remember what I did. (I ran a diff so it should be complete, but it’s almost 2am so who knows.)

For those of you who have no idea what glBlendColorEXT does for you, or how OpenGL blending works at all, I’m going to do a tutorial on that next, actually, because it’s bugged me for a long time that no place on the internet have I found anything but the OpenGL docs about what blending can be used for and how you can do some pretty neat effects with it. Don’t hold me to that, I don’t know when I’ll get to it. As always leave comments, and if I don’t get to you it’s because I’ve forgotten to check this thread, so you can always e-mail me.

--Pat Wilson 17:40, 17 Jun 2005 (CDT)