Adding specific OpenGL extension support to Torque
by Pat Wilson · 01/26/2005 (1:43 am) · 9 comments
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:
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:
www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_minmax.txt.html
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.
You also see I added the function here. You can get the function prototype on the page from the section 'New Procedures and Functions'.
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
In 'platformWin32/winGL.cc' in the 'GL_EXT_Init' function, add the following near the other ones that look like this
Then, down a bit lower, add the console printout, in our case add this
In 'platformWin32/winGLSpecial.cc' add this somewhere, this is the function for the GL logging
Next go to 'platformWin32/platformGL.h' and add a bool to the GLstate struct for your new extension. I added:
You can also add an inline for getting support
And that should do you! I will have to add this support to Mac and if I remember I will update this resource.
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.
The first thing to do is look up the extension you want to support. A great page that I found to do this is:
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:
www.msi.unilim.fr/~porquet/glexts/GL_EXT_blend_minmax.txt.html
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'.
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");andif (!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.
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.
About the author
#2
01/27/2005 (7:31 am)
I love you Pat...
#3
Again great explaination :)
01/28/2005 (12:41 am)
Fabulous resource! Easy to follow. I have looked and looked hoping to find what many of the extentions accually do.. Heres your game without GL_EXT_blend_color, and here it is with GL_EXT_blend_color. That visual aspect would be wonderful but I cant find any images that show off these ext effects.Again great explaination :)
#5
02/01/2005 (11:22 pm)
Sam, I have a tutorial on blending comming up that will hopefully address some of your questions, and everyone elses. Blending modes are a black box to most people, and I'd like to solve that.
#6
04/11/2005 (12:53 pm)
Does anybody have screenshot to show improvement of this resource?
#7
04/28/2005 (5:48 am)
Me too, i'd like to see a screenshot if it's possible, before do changes in Torque.
#8
Any idea ?
05/01/2005 (5:38 pm)
I was wondering if the belding function here is referred only to a color or also to a texture...Any idea ?
#9
01/22/2007 (9:25 pm)
its an oldie....but still a goodie! 
Torque Owner Jorgen Ewelonn