Jump to content
  • Advertisement
Sign in to follow this  
me_here_me

texture rendering [SOLVED]

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am generating a texture, with a red color and varying alpha value. Alpha is 0 for half of the texture and 255 for the other half. But when I display the texture, its shows the entire texture red. Code for generating the texture:
	int fbSize = fbWidth * fbHeight;
	GLubyte *txHexagonData = new GLubyte[fbSize * 4];

	for (int i=0;i<fbSize * 4;){
		txHexagonData[i++] = 255;
		txHexagonData[i++] = 0;
		txHexagonData[i++] = 0;
		if(i > (fbSize/2))
			txHexagonData[i++] = 0;
		else
			txHexagonData[i++] = 255;
	}

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, txHexagon);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 
		fbWidth, fbHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, txHexagonData);

	if (txHexagonData)
		delete [] txHexagonData;


I have debugged to see if data is populated in the array correctly and it does. code for displaying the texture;
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, txHexagon);
	glEnable(GL_TEXTURE_2D);

	glBegin(GL_QUADS);
	glTexCoord2f(0, 0); glVertex2f(-1, -1);
	glTexCoord2f(0, 1); glVertex2f(-1,  1);
	glTexCoord2f(1, 1); glVertex2f( 1,  1);
	glTexCoord2f(1, 0); glVertex2f( 1, -1);
	glEnd();


any hints about why the entire screen is colored red best wishes [Edited by - me_here_me on August 18, 2008 9:10:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
I could be wrong, butI think you need to call glEnable(GL_BLEND) before you start drawing.

Share this post


Link to post
Share on other sites
what is your blend function?

im using:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

and works fine.

are you sure you have anything in the background? so you draw the alpha blended image last.

Share this post


Link to post
Share on other sites
Thanks for the help guys :)

I did not have the right blend function. It worked when I replaced it with the one proposed by Emark.

best

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!