Sign in to follow this  
Genjix

OpenGL wxImage::GetAlpha and OpenGL

Recommended Posts

Hello, As I understand it wxImage::GetData() returns *uchar[3] (RGB) and wxImage::GetAlpha() returns *uchar[1](A). I am using a wxGLCanvas and to load textures I have this function
def LoadTexture(tex_src , tex_id , size):
	tex_id[0] = glGenTextures(1)
	glBindTexture(GL_TEXTURE_2D, tex_id[0])

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

	wximage = wxImage(tex_src)

	size.append(wximage.GetWidth())
	size.append(wximage.GetHeight())

	# i think OpenGL does this for us...
	# either way OpenGL resize is faster & easier
	#if not isCompliant(glImage))
	#	glImage = makeGLCompliant(glImage);

	# how to get the alpha channel together with pixel data
	if wximage.HasAlpha():
		glTexImage2D(GL_TEXTURE_2D , 0 , GL_RGB , wximage.GetWidth(),
				wximage.GetHeight() , 0 , GL_RGB , GL_UNSIGNED_BYTE , wximage.GetData())
	else:
		glTexImage2D(GL_TEXTURE_2D , 0 , GL_RGB , wximage.GetWidth(),
				wximage.GetHeight() , 0 , GL_RGB , GL_UNSIGNED_BYTE , wximage.GetData())

	return tex_id

Any clues on how I can load the image alpha into OpenGL (GL_RGBA) without cocantenating a new pixel array O_O?

Share this post


Link to post
Share on other sites
There is no decent way to do that. The way wxImage stores Alpha in a seperate buffer makes this a problem. You need to make a new buffer and interleave the RGB and the A into the one buffer, and give that to glTexImage2D().

Or use something else to load the images, like DevIL.

Share this post


Link to post
Share on other sites
ok, thank you very much.

I already have an SDL loader, but wanted to reduce the SDL dependency.
This is just what I thought :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this