Textures causing garbage at the bottom of screen

Hello,

My OpenGL program causes some garbage/noise at the bottom of my window when I am trying to texture some things. Does anyone have any ideas as to what could be causing this?

Make sure your texture size is a power of 2, ( 2x2; 4x4 8x8) and that it is mapped properly onto your object. Besides that, if there’s not too much code, could you post the source for us to look at?

Sure, here it is…

#include <stdio.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif /* __APPLE */
#include <GL/glaux.h>

#pragma comment(lib, "GLaux.lib")

GLuint texture[4];
AUX_RGBImageRec * texImage[4];

void init();
void display(void);
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);
AUX_RGBImageRec *LoadBMP(char *Filename);

int main(int argc, char ** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize (500, 500);
	glutInitWindowPosition (100, 100);
	glutCreateWindow(argv[0]);
	init();
	glutReshapeFunc(reshape);
	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutMainLoop();
	
	return 0;
}

void init(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);

	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	texImage[0] = LoadBMP("L7-1.bmp");
	texImage[1] = LoadBMP("L7-2.bmp");
	texImage[2] = LoadBMP("L7-3.bmp");
	texImage[3] = LoadBMP("L7-4.bmp");

	glGenTextures(4, texture);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	//glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128,
		0, GL_RGB, GL_UNSIGNED_BYTE, texImage[0]);

	glBindTexture(GL_TEXTURE_2D, texture[1]);
	glBindTexture(GL_TEXTURE_2D, texture[2]);
	glBindTexture(GL_TEXTURE_2D, texture[3]);

	//texImage[0] = auxDIBImageLoad("L7-1.bmp");
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	glPushMatrix();
	
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);		glVertex3f(-0.5, -0.5, 0.5);
	glTexCoord2f(1.0, 0.0);		glVertex3f(0.5, -0.5, 0.5);
	glTexCoord2f(1.0, 1.0);		glVertex3f(0.5, 0.5, 0.5);
	glTexCoord2f(0.0, 1.0);		glVertex3f(-0.5, 0.5, 0.5);
	glEnd();
	
	glPopMatrix();

	glutSwapBuffers();
}

void reshape(int w, int h)
{
}

void keyboard(unsigned char key, int x, int y)
{
	switch(key) {
	case 27:
		exit(0);

	default:
		break;
	}
}

AUX_RGBImageRec *LoadBMP(char *Filename)
{
	FILE *File=NULL;

	if (!Filename)
	{
		return NULL;
	}

	File=fopen(Filename,"r");

	if (File)
	{
		fclose(File);
		return auxDIBImageLoad(Filename);
	}

	printf("Ahhh hell...
");

	return NULL;
}

Also, if this helps, the texture is a little red, when before it was a little blue, and also, it’s a message, “Hi”, but the first half of the “H” is on the right-hand side of the screen, with garbage at the bottom.

Thats usally a problem with the padding bytes inside a bmp file. Every line inside a bmp file starts at offset divideable by 4 and extra padding bytes are added to the lines to ensure that restriction.
If the bmp loader ignores the padding bytes it will result in the effect you are seeing.

You should not use GLAUX, its buggy as hell and has tons of memory leaks.