Archived

This topic is now archived and is closed to further replies.

QReboundSoftware

Once again... Textures?

Recommended Posts

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]

Share this post


Link to post
Share on other sites
UltimaX    468
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!"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
i think its the hardware which just can handle x^2 textures in memory

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
krez    443
quote:
Original post by QReboundSoftware
And i dont have a business license. Its just sorta a virtual company per se.

if you have no business license, it is not a business, and you can''t be CEO.

while you may think it is great to pretend to run a company that doesn''t exist, it just makes everyone else think you are lame (except maybe the other 12-year-olds claiming to be CEOs).

Share this post


Link to post
Share on other sites
Jeffno10    122
Oi! Leave the kid alone!

I bet half of the ''adult'' companies are much the same. It has no legal standing, but all he means is that is his role and function. It''s all a bit of fun I''m sure, but wait and second... don''t we make computer GAMES?

12 eh? When I was 12, I learned 8086 assembler and learned how to program 13h video mode... THOSE were the days...

Share this post


Link to post
Share on other sites
theZapper    150
hahaha!

All bow to Krez!

So does that mean all I need to do to become a CEO is to make up a name of a company, and tell people about it?

in that case..

TheZapper
CEO Super Duper Thingamy-jigs

"We make stuff" - That''s gonna be my slogan.

---
"When I''m in command, every mission''s a suicide mission" - Zapp Branigan

Share this post


Link to post
Share on other sites
krez    443
quote:
Original post by ShlomiSteinberg
WTF?

i was going with the "type it and it becomes true" angle...

don''t mind me!

Share this post


Link to post
Share on other sites