Skip to main content
gamedev.net
🔒 Locked

Odd Texture Behavior

Started by fathom88 9 replies 1k views
Original Post
fathom88
fathom88
I've been working with Textures for a little time. They have worked fine until now. I did a translate then re-applied my texture. The texture looks funny. It is in the place I expected and is the correct size. The texture just looks like it's in a lower resolution. This is what I do. glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(...); glBindTexture(GL_TEXTURE_2D, MyTex); glBegin(GL_QUADS); glTexCoord2d(0.0, 1.0); glVertex2d(Left, Top); glTexCoord2d(1.0, 1.0); glVertex2d(Right, Top); glTexCoord2d(1.0, 0.0); glVertex2d(Right, Bottom); glTexCoord2d(0.0, 0.0); glVertex2d(Left, Bottom); glEnd(); //detach texture glBindTexture(GL_TEXTURE_2D, 0); SwapBuffers(WinDC); Like I said, it's in the correct position and is the correct size as far as I can tell. The textured image just looks off. This is strange. Any ideas? I have never seen this before. Thanks in advance.
cowsarenotevil
cowsarenotevil
Perhaps you could post a screenshot of what it looked like before you did this and what it looks like in its "odd" state. I'm not entirely sure what you mean.

Your problem could just be a result of the texture's mipmapping, though. Try loading the texture into memory such that it doesn't enable mipmapping and see if you still have this problem.
-~-The Cow of Darkness-~-
fathom88
fathom88
After some careful observations, I've come to the realization the image is being squeezed by a tiny bit. Enough to make the image look slightly off. I'm not sure why it's happening. Here is what I'm doing.

1. I create a texture map the size of my window.

2. I copy my entire render window/view port into the texture. This way I have a stored image of my render.

3. I perform a translation.

4. I draw rectangle with the my texture bond to it.

Shouldn't it produce an image that has moved by the translation amount? I don't see why the textured image should be squeezed. Thanks for the help.
cowsarenotevil
cowsarenotevil
Hmm. That is rather strange. Can you perhaps post the full before/after code? Nothing comes to mind offhand. It's strange that it would work up until you translated it. Are you moving it along the Z axis? That could cause it to jump to a lower resolution mipmap of the image, like I mentioned, but that doesn't really sound like what you're talking about.
-~-The Cow of Darkness-~-
bballmitch
bballmitch
i've had a problem like this, but it involved scaling my texture. Do you ever scale it?
Mitchen Games
derethor
derethor
Quote:
Original post by fathom88
1. I create a texture map the size of my window.


textures in basic OpenGL must be "power of 2" squared size (i meant 256x256, 512x512, etc)... can you check it?

I suggest you to check GLIntercept, a great app to debug opengl....
-- Signed, Javier Loureiro Varela http://www.codepixel.com
fathom88
fathom88
As a matter of fact, I sized my texture based on the size of my window (in pixels). And yes, the texture sizes were off (not powers of two). I fixed that mistake. However, the problem still exists. I only do a transform. I've been using this trick without problems. I tried manually moving the texture by shifting the values of Top, Bottom, Left, and Right; doing myself what glTranslate does.

Here are the options I set for the texture. I don't think I'm missing anyting.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Thanks for the help. It's appreciated.
steeg
steeg
I once had a texture that was also showing up funny and it turned out to be because I wasn't converting the source bitmap into Byte format. I'm not sure what you're using to load the files, but I was using DevIL library and the following code after loading the image solved my problem:
ilConvertImage(IL.IL_RGB, IL.IL_BYTE);

Maybe it helps...
Nit
Nit
when are you calling gluPerspective and what are the values you are setting?

EDIT (more thoughts):
My initial guess is that your aspect is off. Since the values may be inaccurate in gluPerspective(..), your texture will get warped as it moves away from the center of your viewport.
_the_phantom_
_the_phantom_
Quote:
Original post by derethor
textures in basic OpenGL must be "power of 2" squared size (i meant 256x256, 512x512, etc


no.
There is no requirement that the textures are square, the sides must just be a power of two, so 256x512 is prefectly valid on default OpenGL.

fathom88
fathom88
I think you're on the right track. Here is what I do to set up the window.

//The size of my window in pixels
glViewport(0, 0, Width, Height);
.
.
//I use my own coordinate system for easier ploting,
//but it scales to my window
gluOrtho2D(Left, Right, Bottom, Top);
.
.

After rendering my image to the window, I make a copy the rendered image into the texture.

glBindTexture(GL_TEXTURE_2D, mRenderTexture);
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0,0, Width, Height);
glBindTexture(GL_TEXTURE_2D, 0);

I think the problem is my texture does not scale exactly to my window. My window's dimensions are never powers of 2 like my texture. I found an example of some scaling texture and tried it. However, it do not fix my problem.

ScaledWidth = (Width / TexWidth);
glTexCoord2f(ScaledWidth, 0); //instead of 1,0

I think what I'm doing is pretty non-standard. I might be better off simply trying something new. Thanks anyways.

Topic Locked

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

Sign in to reply to this topic.