Jump to content
  • Advertisement
Sign in to follow this  
ScottC

OpenGL Odd 2D OpenGL textured tri strip bug

This topic is 4427 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

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;
}

Share this post


Link to post
Share on other sites
Advertisement
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);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites


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<Image> GameImages;
Whatever happens the be the second image thats push_back'd into it tends to have the pink lines. My question is why?

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
What is the color of invisible parts of your image?


pink.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
without looking at the code...
Im going to Guess that this is one of the Texture Mode flags being set wrong when you load your texture data
Wrap vs Clamp edges, etc.
Thats just off the top of my head, someone else point out the real keywords...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!