Once again... Textures?

Started by
14 comments, last by QReboundSoftware 20 years, 8 months ago
Ok, here it is. I started learning OpenGL about 6-7 months back, and i got to NeHe's 6th tutorial. Then i had to stop, because i couldnt get textures to work. So i learned DX. I thaught i would try OpenGL again, and im at lesson 6, and i am having the exact same problem. I think the problem is when im trying to either load or display my image. Here are the three functions that take care of that. Load Textures:

int	LoadTextures()
{
	int Status=false;
	AUX_RGBImageRec *TextureImage[1];
	memset(TextureImage, 0, sizeof(void *)*1);
	if(TextureImage[0]=LoadBMP("C:\\Damian\\PROGRAMMINGPROJECTS\\FireflyOpenGL\\Data\\Images\\File.bmp"))
	{
		Status=true;
		glGenTextures(1, &Texture[0]);
		glBindTexture(GL_TEXTURE_2D, Texture[0]);
		glTexImage2D(GL_TEXTURE_2D, 0,3,TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	}
	if(TextureImage[0])
	{
		if(TextureImage[0]->data)
		{
			memset(TextureImage[0]->data, 0, sizeof(TextureImage[0]->data));
		}
		memset(TextureImage[0], 0, sizeof(TextureImage[0]));
	}
	return(Status);
}
DrawGLScene:

int GLDrawScene(GLvoid)														//Draws the OpenGL Scene

{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);						//Clear the Screen each frame

	//World Stuff

	glLoadIdentity();														//Load the Identity

	glTranslatef(-1.5f, 0.0f, -12.0f);										//Drawing

	glRotatef(RotX, 1.0f, 0.0f, 0.0f);
	glRotatef(RotY, 0.0f, 1.0f, 0.0f);
	glRotatef(RotZ, 0.0f, 0.0f, 1.0f);
	glBindTexture(GL_TEXTURE_2D, Texture[0]);
	//Pyramid

	glBegin(GL_TRIANGLES);
	
	//Top Point(front)

	glTexCoord2f(0.5f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
	
	//Bottom Left hand corner(front)

	glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-1.0f,1.0f);
	
	//Bottom Right Hand Corner(front)

	glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f,1.0f);
	
	//Top Point(Right)

	glTexCoord2f(0.5f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
	
	//Bottom Left hand corner(Right)

	glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
	
	//Bottom Right Hand Corner(Right)

	glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f,1.0f);
	
	//Top Point(back)

	glTexCoord2f(0.5f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
	
	//Bottom Left hand corner(back)

	glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-1.0f, -1.0f);
	
	//Bottom Right Hand Corner(back)

	glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f,-1.0f);
	
	//Top Point(left)

	glTexCoord2f(0.5f, 0.0f); glVertex3f(0.0f, 1.0f, 0.0f);
	
	//Bottom Left hand corner(left)

	glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,-1.0f,-1.0f);
	
	//Bottom Right Hand Corner(left)

	glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -1.0f,1.0f);
	
	glEnd();
	//World Stuff

	glLoadIdentity();
	glTranslatef(1.5f, 0.0f, -12.0f);
	glRotatef(RotX, 1.0f, 0.0f, 0.0f);
	glRotatef(RotY, 0.0f, 1.0f, 0.0f);
	glRotatef(RotZ, 0.0f, 0.0f, 1.0f);
	//Cube

	glBegin(GL_QUADS);
	//Top

	
	glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f, 1.0f,1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f, 1.0f,1.0f);
	
	glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f,-1.0f);
	
	glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f,-1.0f);
	//Front

	
	glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 1.0f);

	glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
	
	glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
	//Left

	
	glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
	
	glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, 1.0f,-1.0f);

	glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
	//Bottom

	
	glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 1.0f);
	
	glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f,-1.0f,-1.0f);
	
	glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
	//Back

	
	glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f, 1.0f,-1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f, 1.0f,-1.0f);
	
	glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f,-1.0f,-1.0f);

	glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,-1.0f,-1.0f);
	//Right

	
	glTexCoord2f(0.0f,0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
	
	glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
	
	glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, -1.0f,-1.0f);
	
	glTexCoord2f(0.0f,1.0f); glVertex3f( 1.0f, 1.0f,-1.0f);
	glEnd();
	//Rotation

	RotX+=0.1f;
	RotZ+=0.2f;
	RotY+=0.3f;
	return(true);															//Return Success

}
LoadBMP:

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

	if(!Filename)
	{
		return(NULL);
	}
	File=fopen(Filename, "r");
	if(File)
	{
		fclose(File);
		return(auxDIBImageLoad(Filename));
	}
	return(NULL);
}
Here is The specific problem: It doesnt display the actual texture. I tried removing the color, thinking it was overriding the picture or something, but it didnt work. If you want any other part of the code tell me. I would have come to you 2 days ago when i started having the problem, but i wanted to try to find it myself. P.S. Oh ya, and it also wont display anything but a screenshot of my desktop in Fullscreen mode if that helps. ______________________________ Quantum CEO of Quantum Rebound Software Website Up Soon [edited by - QReboundSoftware on August 9, 2003 9:20:32 AM]
______________________________QuantumCEO of Quantum Rebound SoftwareWebsite Up Soon
Advertisement
is your image size in powers of 2?
Use gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); then you don''t have to worry about the texture being in the power of 2. As far as I know, it resizes the textures for you.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"
Oh ya, i forgot about the whole Power of two thing. Why is that anyway?


______________________________
Quantum
CEO of Quantum Rebound Software
Website Up Soon
______________________________QuantumCEO of Quantum Rebound SoftwareWebsite Up Soon
Ok, its working now. Thanks! Ill remember to tell my texture artist that it has to be a power of two


______________________________
Quantum
CEO of Quantum Rebound Software
Website Up Soon
______________________________QuantumCEO of Quantum Rebound SoftwareWebsite Up Soon
i think its the hardware which just can handle x^2 textures in memory
quote:Original post by Anonymous Poster
i think its the hardware which just can handle x^2 textures in memory


there are a lot of extensions to use other sizes, but anything thats not 2^x is slow and id rather have a 512x1024 texture and only use 512x800 than using any "odd" sizes.

also
"if(TextureImage[0]) {
if(TextureImage[0]->data) {
memset(TextureImage[0]->data, 0, sizeof(TextureImage[0]->data));
}
memset(TextureImage[0], 0, sizeof(TextureImage[0]));
}"

what is this supposed to do? you should free the memory, not set it to zero. this isnt java and even there youd set the pointer to 0, not the memory.
f@dzhttp://festini.device-zero.de
Sorry. It says to use the Free() function, but it wasnt working with my compiler...
Oh, and how would i calculate the normals for the sides of a pyramid? *is working on lighting since he got Textures finished, and nehe doesnt explain it, and i didnt want to waste another thread on it* I know it has to do with algebra, but im only 12, and im not at that level :S
______________________________
Quantum
CEO of Quantum Rebound Software
Website Up Soon

[edited by - QReboundSoftware on August 9, 2003 1:18:40 PM]
______________________________QuantumCEO of Quantum Rebound SoftwareWebsite Up Soon
You''re a CEO at age 12??
Ya. Sorta. Its not a really big company yet, its only been up for about 2 months. And i dont have a business license. Its just sorta a virtual company per se.


______________________________
Quantum
CEO of Quantum Rebound Software
Website Up Soon
______________________________QuantumCEO of Quantum Rebound SoftwareWebsite Up Soon

This topic is closed to new replies.

Advertisement