Skip to main content
gamedev.net
🔒 Locked

problem

Started by Xano Oct 29, 2005 at 11:25 AM 5 replies 550+ views
Original Post
Xano
Xano
Hey, I've decided to make a Sonic game. But my background is getting weird, and I don't know why. I'm using mipmapping and the size of background is 511 x 249. Here's the loading code:

	if (TextureImage[0]=LoadBMP("Data/map/ghground.bmp"))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures(1, &texture[1]);					// Create The Texture

		// Create MipMapped Texture
		glBindTexture(GL_TEXTURE_2D, texture[1]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )

		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // ( NEW )
	}



Here's the code that makes the background:

	glBindTexture(GL_TEXTURE_2D, texture[0]);
	
	glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-100.0f, -1.5f,  1.5f);
		glTexCoord2f(30.0f, 0.0f); glVertex3f( 100.0f, -1.5f,  1.5f);
		glTexCoord2f(30.0f, 1.0f); glVertex3f( 100.0f,  1.5f,  1.5f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-100.0f,  1.5f,  1.5f);
	glEnd();



Here's the background that's loaded: Image And here's a pic of what's wrong with background: Image Thanks, Xano
Undeadlnsanity
Undeadlnsanity
Your image is loading fine, but you're stretching it! You'll need to resize the image to the appropriate size which will stop the stretching.
Xano
Xano
Quote:
Original post by Undeadlnsanity
Your image is loading fine, but you're stretching it! You'll need to resize the image to the appropriate size which will stop the stretching.


What's "the appropriate size"?
dbzprogrammer
dbzprogrammer
Hmmm.... I think it's your texture coordinates for the verticies... Usually they are 0.0f to 1.0f... I think that's where your fault is and thats why it's stretching.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
zedzeek
zedzeek
with backgrounds etc u dont wanna use mipmapping
with a 511 x 249 sized texture u have 2 options
A/ use NPOT texture (or texture_rectangel etc) works on latest hardware
B/ create a 512x256 sized texture and stick the image in there in the bottom left corner and use texture coords (0,0)->(511.0/512.0,249.0/256.0)
Xano
Xano
I don't get it -.- could anyone explain any simplier way, I'm an OPenGL nuub
NextS
NextS
Hi,

I don't know where precisely the problem is, but I think the first thing you should try is use texture coordinates in the range from 0.0 to 1.0.

glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-100.0f, -1.5f, 1.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 100.0f, -1.5f, 1.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 100.0f, 1.5f, 1.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-100.0f, 1.5f, 1.5f);
glEnd();

This should display the image the way it is loaded into memory (scaled to the vertex coordinates given)

With 30 in the x-direction your texture may be repeaded 30 times in the range from -100 to 100 depending on the settings. ( is this perhaps wanted? )

The next thing... it looks like your texture is painted with wrong vertex coordinates. What projection matrix did you set up ? Are all objects rendered with the same matrix stack ?

FYI:
When you use glTexImage2D to create the texture, there is a limitation in texture size: The tex coords have to be a potency of 2. But when using gluBuild2DMipMaps, the function automatically scales the texture to the next Level. So this should not be the problem I think.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.