Skip to main content
gamedev.net
🔒 Locked

Odd 2D OpenGL textured tri strip bug

Started by ScottC 8 replies 1.7k views
Original Post
ScottC
ScottC
The problem is that when I move an image, for some reason it flashes pink lines on the bottom and top of the image. Any idea whats causing this? Heres the app so you can see it for yourself. http://files.filefront.com/OGLSpaceShooterzip/;5224896;;/fileinfo.html Draw code:

bool Image::Draw(float X, float Y){
	glBindTexture(GL_TEXTURE_2D, (*iIndex));
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0);
	glBegin(GL_TRIANGLE_STRIP);
		glTexCoord2f(0.0f,(float)iHeight/(float)iFullHeight);
		glVertex2f(X, Y);

		glTexCoord2f((float)iWidth/(float)iFullWidth, (float)iHeight/(float)iFullHeight);
		glVertex2f(X + (float)iWidth, Y);

		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(X, Y + (float)iHeight);

		glTexCoord2f((float)iWidth/(float)iFullWidth,0.0f);
		glVertex2f(X + (float)iWidth, Y + (float)iHeight);
	glEnd();
	glDisable(GL_ALPHA);
	glDisable(GL_BLEND);
	return true;
}
nts
nts
Quote:
Original post by ScottC
The problem is that when I move an image, for some reason it flashes pink lines on the bottom and top of the image. Any idea whats causing this?

Heres the app so you can see it for yourself.
http://files.filefront.com/OGLSpaceShooterzip/;5224896;;/fileinfo.html

Draw code:
bool Image::Draw(float X, float Y){	glBindTexture(GL_TEXTURE_2D, (*iIndex));	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glEnable(GL_ALPHA_TEST);	glAlphaFunc(GL_GREATER, 0);	glBegin(GL_TRIANGLE_STRIP);		glTexCoord2f(0.0f,(float)iHeight/(float)iFullHeight);		glVertex2f(X, Y);		glTexCoord2f((float)iWidth/(float)iFullWidth, (float)iHeight/(float)iFullHeight);		glVertex2f(X + (float)iWidth, Y);		glTexCoord2f(0.0f, 0.0f);		glVertex2f(X, Y + (float)iHeight);		glTexCoord2f((float)iWidth/(float)iFullWidth,0.0f);		glVertex2f(X + (float)iWidth, Y + (float)iHeight);	glEnd();	glDisable(GL_ALPHA);	glDisable(GL_BLEND);	return true;}


Shouldn't glDisable(GL_ALPHA); actually be glDisable(GL_ALPHA_TEST);

ScottC
ScottC
Quote:
Original post by nts
Quote:
Original post by ScottC
The problem is that when I move an image, for some reason it flashes pink lines on the bottom and top of the image. Any idea whats causing this?

Heres the app so you can see it for yourself.
http://files.filefront.com/OGLSpaceShooterzip/;5224896;;/fileinfo.html

Draw code:
bool Image::Draw(float X, float Y){	glBindTexture(GL_TEXTURE_2D, (*iIndex));	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glEnable(GL_ALPHA_TEST);	glAlphaFunc(GL_GREATER, 0);	glBegin(GL_TRIANGLE_STRIP);		glTexCoord2f(0.0f,(float)iHeight/(float)iFullHeight);		glVertex2f(X, Y);		glTexCoord2f((float)iWidth/(float)iFullWidth, (float)iHeight/(float)iFullHeight);		glVertex2f(X + (float)iWidth, Y);		glTexCoord2f(0.0f, 0.0f);		glVertex2f(X, Y + (float)iHeight);		glTexCoord2f((float)iWidth/(float)iFullWidth,0.0f);		glVertex2f(X + (float)iWidth, Y + (float)iHeight);	glEnd();	glDisable(GL_ALPHA);	glDisable(GL_BLEND);	return true;}


Shouldn't glDisable(GL_ALPHA); actually be glDisable(GL_ALPHA_TEST);


Thanks for pointing that out.
ScottC
ScottC
I'd just like to point out that the problem still isn't solved.
kordova
kordova
For those of us without (or refusing to boot into) Windows, could you post an image of the issue? Myself aside, I am certain that others with Windows would be more willing to help if it did not involve downloading and running an application.

Also, can you show us your rendering code or at least describe it or steps you have taken to isolate the problem?

Cheers.
ScottC
ScottC


I came up with an image class, and oddly enough, whatever image is in index 1 of my vector array ends up with the pink issue when rendering it.
ScottC
ScottC
class Image{public:	Image(GLuint *Index, int Width, int Height, int iFullWidth, int iFullHeight, char *File);	bool Draw(int X, int Y, int Width, int Height);	bool Draw(float X, float Y);private:	char *iFile;	int  iHeight, iWidth, iFullHeight, iFullWidth;	GLuint *iIndex;};Image::Image(GLuint *Index, int Width, int Height, int FullWidth, int FullHeight, char *File){	iFile		= File;	iIndex		= Index;	iHeight		= Height;	iWidth		= Width;	iFullHeight = FullHeight;	iFullWidth	= FullWidth;}bool Image::Draw(float X, float Y){	glBindTexture(GL_TEXTURE_2D, (*iIndex));	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	glEnable(GL_ALPHA_TEST);	glAlphaFunc(GL_GREATER, 0);	glBegin(GL_TRIANGLE_STRIP);		glTexCoord2f(0.0f,(float)iHeight/(float)iFullHeight);		glVertex2f(X, Y);		glTexCoord2f((float)iWidth/(float)iFullWidth, (float)iHeight/(float)iFullHeight);		glVertex2f(X + (float)iWidth, Y);		glTexCoord2f(0.0f, 0.0f);		glVertex2f(X, Y + (float)iHeight);		glTexCoord2f((float)iWidth/(float)iFullWidth,0.0f);		glVertex2f(X + (float)iWidth, Y + (float)iHeight);	glEnd();	glDisable(GL_ALPHA_TEST);	glDisable(GL_BLEND);	return true;}//in the init game function	ImageIndex = 0;	ilInit();	ilEnable(IL_ORIGIN_SET);	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);	glGenTextures(MAXIMAGES, texture);	oglLoadTexture("Images/Backgrounds/BG0_space_1.png");	oglLoadTexture("Images/Backgrounds/BG1_planet_big_1.png");	oglLoadTexture("Images/Backgrounds/BG1_planet_small_1.png"); 	oglLoadTexture("Images/Enemies/SPRITE_small_1.png");	oglLoadTexture("Images/Backgrounds/BG1_planet_big_1.png");//thats the relevant code//yes I realize I somewhat suck at coding.void GraphicsSystem::oglLoadTexture(char *filename){	glBindTexture(GL_TEXTURE_2D, texture[ImageIndex]);	ilLoadImage(filename);	ILuint img;	ilGenImages(1, &img);	ilBindImage(img);	ilLoadImage(filename);	int RealWidth, RealHeight;	RealWidth = ilGetInteger(IL_IMAGE_WIDTH);	RealHeight = ilGetInteger(IL_IMAGE_HEIGHT);	if (ilGetInteger(IL_IMAGE_FORMAT) == IL_RGBA){		PadImage(4);	} else	if (ilGetInteger(IL_IMAGE_FORMAT) == IL_RGB){		PadImage(3);	}	glBindTexture(GL_TEXTURE_2D, texture[ImageIndex]);	if (ilGetInteger(IL_IMAGE_FORMAT) == IL_RGBA){		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());	} else	if (ilGetInteger(IL_IMAGE_FORMAT) == IL_RGB){		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());	}	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	glEnable(GL_TEXTURE_2D);//	GameImages[ImageIndex] = new Image(&texture[ImageIndex], RealWidth, RealHeight, ilGetInteger(IL_IMAGE_HEIGHT), //							 ilGetInteger(IL_IMAGE_WIDTH), filename);	GameImages.push_back(Image(&texture[ImageIndex], RealWidth, RealHeight, ilGetInteger(IL_IMAGE_HEIGHT), 								ilGetInteger(IL_IMAGE_WIDTH), filename));	ilDeleteImages(1, &img);	ImageIndex++;}bool PadImage(int bpp){	int ImgWidth,ImgHeight,NewImgWidth,NewImgHeight;	ImgWidth = ilGetInteger(IL_IMAGE_WIDTH);	ImgHeight = ilGetInteger(IL_IMAGE_HEIGHT);	NewImgWidth = roundUpToPow2(ImgWidth);	NewImgHeight = roundUpToPow2(ImgHeight);	ILubyte *data = ilGetData();	if (NewImgWidth != ImgWidth || NewImgHeight != ImgHeight){		char* tempdata = new char[((NewImgWidth*bpp)*NewImgHeight)];		memset(tempdata, 255, (NewImgWidth*bpp)*NewImgHeight);		for (int y = 0; y < ImgHeight; y++){			for (int x = 0; x < ImgWidth*bpp; x++){				tempdata[x+(y*NewImgWidth*bpp)] = (char)data[x+(y*ImgWidth*bpp)];			}		}		ilTexImage(NewImgWidth,NewImgHeight,1,bpp,ilGetInteger(IL_IMAGE_FORMAT),ilGetInteger(IL_IMAGE_TYPE),tempdata);		delete[] tempdata;	}	return true;}


so I have this: std::vector GameImages;
Whatever happens the be the second image thats push_back'd into it tends to have the pink lines. My question is why?
Ezbez
Ezbez
What is the color of invisible parts of your image?
ScottC
ScottC
Quote:
Original post by Ezbez
What is the color of invisible parts of your image?


pink.

Topic Locked

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

Sign in to reply to this topic.