2

I need to blend a few image together into a single one, pretty much as what's described here: OpenGL - mask with multiple textures.
I used the solution that is proposed there, but there's an issues with the glBlendFuncSeparate method.

Turns out that this method was introduced in later openGL versions, and according to my gl.h file the version I'm using is 1.
After much searching and reading I realized that this is what I have to work with and that I can't just upgrade my openGL version.

I went ahead and downloaded GLEW.
I added glew.h and glew.c into my VS10 project, defined GLEW_BUILD and now it finally compiles without complaining about glBlendFuncSeparate, but when I run the program it crashes when it tries to call the method, saying Access Violation, I guess that it points to NULL and then crashes when that's being run.

I continued reading and searching on this, and from what I understand, I need to use OpenGl Extensions to make it work.
If what's written in Using OpenGL extensions On Windows is correct then I'm missing something.
Let's say I do everything it says, I "download and install the latest drivers and SDKs for your graphics card" and then compile it, even if it runs on my machine, I see no guarantee that it won't crash on someone else's machine, since they might not have done the same.

I have two questions:

  1. Am I missing something here? this whole process seems way too complicated, and environment dependent.
  2. Is there an alternative for using glBlendFuncSeparate in this kind of a scenario?
Community
  • 1
  • 1
Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • 2
    Did you [call `glewInit()`](http://glew.sourceforge.net/basic.html) after you create your GL context? – genpfault Oct 17 '13 at 14:06
  • Oh damn. You're right. I did call `glewInit`, but I haven't noticed that it returned with an error. The problem was that I called it before I created the gl context. Thanks! – Nitzan Tomer Oct 17 '13 at 14:54

1 Answers1

2

You don't need glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO); to use trick described in OpenGL - mask with multiple textures. Yes, you can't added color directly to alpha channel, like described in previous example, but you can be little tricky.

During writing your mask just disable writting all color channels, except alpha:

glColorMask(false, false, false, true);

and enable multiplying mask's alpha on background alpha-channel:

glBelndFunc(GL_ZERO, GL_SRC_ALPHA);

After writing bitmask, don't forget setup your glColorMask back.

glColorMask(true, true, true, true);

//-----------------------------------------------------------------------------------------------------------------------

And yes, you need mask with information in alpha channel:

1) It's can be done with GIMP (very simple, but required GIMP knowlege).

2) You can write you own rootine, for pushing color information to alpha channel, before mask texture creation (it's very simple - just few lines of code).

3) Or just use GL_ALPHA "format" attribute in glTexImage2D for mask texture. This flag just writes bitmaps color to texture alpha channel.

Community
  • 1
  • 1
xmash
  • 61
  • 6
  • 1
    Thanks for the info. I no longer use this, so I can't check your suggestions, hopefully it will help others in the future. – Nitzan Tomer Oct 30 '14 at 13:31