Skip to main content
gamedev.net
🔒 Locked

texture rendering [SOLVED]

Started by me_here_me Aug 18, 2008 at 7:51 AM 3 replies 750+ views
Original Post
me_here_me
me_here_me
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]
lol
lol
I could be wrong, butI think you need to call glEnable(GL_BLEND) before you start drawing.
Placeholder for better sig.
me_here_me
me_here_me
thanks for the reply,

No it behaves in the similar manner even with glEnable(GL_BLEND);

Emark
Emark
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.
me_here_me
me_here_me
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.