PDA

View Full Version : 2D texture issue with pink lines appearing on the texture



07-07-2006, 06:53 PM
my original thread is here: http://www.gamedev.net/community/forums/topic.asp?topic_id=402259

The issue is that pink lines appear above and below one texture for some odd reason. Clamping got rid of the line on the bottom, but I don't know what to do on the top.

Copied and pasted information:
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_TEST);
glDisable(GL_BLEND);
return true;
}

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_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,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,ilGetInt eger(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?

sqrt[-1]
07-07-2006, 09:09 PM
The problems is with your padding of images up to the next power of two image size.

The easy fix is to change the line:
memset(tempdata, 255, (NewImgWidth*bpp)*NewImgHeight);

To:

memset(tempdata, 0, (NewImgWidth*bpp)*NewImgHeight);

(I also hope when you say you are clamping, you are using GL_CLAMP_TO_EDGE)

sqrt[-1]
07-07-2006, 09:31 PM
Additional:

The resaon it was only showing up on your second texture is you have these lines somewhere in your frame loop:

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);


The thing is, you do not bind any texture before this, so it will apply these settings to whatever texture was bound last. In this case it is texture 3..

Your rendering frame looks like:

wglSwapBuffers(0x24010741); = true
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.000000,1024.000000,768.000000,0.000000,1 0.000000,-10.000000);
glMatrixMode(GL_MODELVIEW);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.000000,1024.000000,768.000000,0.000000,1 0.000000,-10.000000);
glMatrixMode(GL_MODELVIEW);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glBindTexture(GL_TEXTURE_2D,1);
glColor4f(1.000000,1.000000,1.000000,1.000000);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.000000);
glBegin(GL_TRIANGLE_STRIP); Tex=(0,1) Color()
glTexCoord2f(0.000000,0.750000);
glVertex2f(212.000000,0.000000);
glTexCoord2f(0.585938,0.750000);
glVertex2f(812.000000,0.000000);
glTexCoord2f(0.000000,0.000000);
glVertex2f(212.000000,768.000000);
glTexCoord2f(0.585938,0.000000);
glVertex2f(812.000000,768.000000);
glEnd();
glDisable(GL_ALPHA); glGetError() = GL_INVALID_ENUM
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,2);
glColor4f(1.000000,1.000000,1.000000,1.000000);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.000000);
glBegin(GL_TRIANGLE_STRIP); Tex=(0,2) Color()
glTexCoord2f(0.000000,0.664063);
glVertex2f(12.000000,15.469999);
glTexCoord2f(0.664063,0.664063);
glVertex2f(97.000000,15.469999);
glTexCoord2f(0.000000,0.000000);
glVertex2f(12.000000,100.470001);
glTexCoord2f(0.664063,0.000000);
glVertex2f(97.000000,100.470001);
glEnd();
glDisable(GL_ALPHA); glGetError() = GL_INVALID_ENUM
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,3);
glColor4f(1.000000,1.000000,1.000000,1.000000);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.000000);
glBegin(GL_TRIANGLE_STRIP); Tex=(0,3) Color()
glTexCoord2f(0.000000,0.937500);
glVertex2f(612.000000,37.127998);
glTexCoord2f(0.931641,0.937500);
glVertex2f(1089.000000,37.127998);
glTexCoord2f(0.000000,0.000000);
glVertex2f(612.000000,517.127991);
glTexCoord2f(0.931641,0.000000);
glVertex2f(1089.000000,517.127991);
glEnd();
glDisable(GL_ALPHA); glGetError() = GL_INVALID_ENUM
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glColor4f(0.000000,0.000000,0.000000,1.000000);
glBegin(GL_TRIANGLE_STRIP); Color()
glVertex2f(0.000000,0.000000);
glVertex2f(212.000000,0.000000);
glVertex2f(0.000000,768.000000);
glVertex2f(212.000000,768.000000);
glEnd();
glFlush();
wglSwapBuffers(0x24010741); = true


// Next frame


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.000000,1024.000000,768.000000,0.000000,1 0.000000,-10.000000);
glMatrixMode(GL_MODELVIEW);

//ARRGH! you are setting texture parameters without binding a texture! - using last bound
texture from previous frame which is texture 3!

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.000000,1024.000000,768.000000,0.000000,1 0.000000,-10.000000);
glMatrixMode(GL_MODELVIEW);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);

....

First, fix the above "loose" texture parameter setting.
Next, you now have two solutions to your problem, Use GL_NEAREST filtering on your textures when setting them up. or use the solution in the previous post.

07-07-2006, 11:27 PM
Thanks for the help, I appreciate it. Everything is working great now.

zeoverlord
07-08-2006, 03:14 AM
And don't ever use super pink instead of alpha.