Jump to content

  • Log In with Google      Sign In   
  • Create Account

Create a new texture from two blended textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 grasshop   Members   -  Reputation: 120

Like
0Likes
Like

Posted 07 September 2012 - 07:57 PM

Hi guys, I am trying to create a new texture from a background texture but with it's alpha values set from the colour gradient of another texture. Ie like this:

Posted Image

This is a framework of the C++ code I am using:

unsigned tex_aft(int tex, int copy_tex)
{
	//tex is the texture to set the alpha to, copy_tex is the texture to take the colour gradients from for the alpha values
	GLuint texture = tex, copy_texture = copy_tex;
	glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
	glColor4f(1,1,1,1);
	glClear(GL_COLOR_BUFFER_BIT);
	glDisable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, texture);
	int w, h;
	glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH, &w);
	glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT, &h);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_COLOR);
	glBindTexture(GL_TEXTURE_2D, copy_texture);
	char* bitmap = new char[(h<<(lgpp2(w)+2))|2];  //lgpp2() function is used to get powers of two
	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
	GLuint tex_new;
	glGenTextures(1, &tex_new);
	glBindTexture(GL_TEXTURE_2D, tex_new);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, void(bitmap));
	delete[] bitmap;
	glPopAttrib();
	return tex_new;
}

But from what I know you can't use glBlendFunc to blend bound textures like this, all this code winds up doing is returning a straight replica of the copy_tex. So does anybody here please know what code I could use to blend the two textures like I have described and create a new texture from this?

Thanks for any help.

Edited by grasshop, 07 September 2012 - 08:07 PM.


Sponsor:

#2 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 08 September 2012 - 02:10 AM

It depends a little on your requirements. If you only need to do it once, you may as well do it "off-line". That is, you can do it yourself without using OpenGL.

If you have real-time requirements, using OpenGL to do it seems like a good idea. The usual solution is to use a Frame Buffer Object.

However, I think you should to abandon the deprecated legacy opengl. With shaders, you get it exactly the way you want it.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#3 grasshop   Members   -  Reputation: 120

Like
0Likes
Like

Posted 08 September 2012 - 03:55 PM

Thanks for the help, I did it manually a lot better. Posted Image

Edited by grasshop, 08 September 2012 - 09:11 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS