Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411991 Posts in 69441 Topics- by 58486 Members - Latest Member: Fuimus

June 17, 2024, 01:16:09 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Gaps around me polys!
Pages: [1]
Print
Author Topic: Gaps around me polys!  (Read 2881 times)
TeaAndBiscuits
Level 0
***


View Profile
« on: January 07, 2009, 11:37:49 AM »

Hello, I'm not really a graphics guy so I'm probably doing something REALLY stoopid. I hope some one can help!

I'm writing a new 3D engine in OpenGL. All I'm doing is rendering rows of cubes using
glBegin( GL_QUADS );
glVertex3f(...);
etc etc
glEnd();

Also I have setup a single texture (256*256) which is made up of 32*32 textures (so I just index this texture for each tile surface) to save me having to load in each texture before rendering.

Between my quads I get thin black lines, not between every quad but enough to look rubbish.

Hope this is enough detail. If not I'll gladly tell you more  Beer!
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #1 on: January 07, 2009, 11:49:19 AM »

Make sure your texture coordinates fall exactly within your texture pixels. Keep in mind that if you have linear filtering on, opengl will blur the pixels on the edges with the pixels directly next to them, so even if your texture coordinates are exactly on the edge of your desired pixels, it will blur them with the line of pixels that shouldn't be visible.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
TeaAndBiscuits
Level 0
***


View Profile
« Reply #2 on: January 07, 2009, 11:54:44 AM »

Yep. That fixed it. I changed
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,   GL_LINEAR);

to

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,   GL_NEAREST);

Cheers  Beer!
Logged
Javilop
Level 2
**



View Profile
« Reply #3 on: January 07, 2009, 11:58:14 AM »

You don't have to change the filter. Just:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP );
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #4 on: January 07, 2009, 11:59:16 AM »

You're going to want to have linear filtering on unless you're doing pixelart textures, so a better solution would be to make sure your texture coordinates get adjusted down slightly below what they actually should be

You don't have to change the filter. Just:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP );

That won't help him if this is happening within the texture and not on the edge.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Javilop
Level 2
**



View Profile
« Reply #5 on: January 07, 2009, 12:01:51 PM »

Quote
make sure your texture coordinates get adjusted down slightly below what they actually should be

I think this is correct, but dosen't give border artifacts (it gives blurring artifacts). But yes, he should adjust texel to pixel on the screen. Using glortho and a small displacement of the camera of -1 (If I remember well, I've lost a test I made loooooong time ago).
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #6 on: January 07, 2009, 12:04:49 PM »

I think this is correct, but dosen't give border artifacts (it gives blurring artifacts). But yes, he should adjust texel to pixel on the screen. Using glortho and a small displacement of the camera of -1 (If I remember well, I've lost a test I made loooooong time ago).

I don't think I follow you. His problem is getting blur from linear filtering when hes mapping a tile within a larger image.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Javilop
Level 2
**



View Profile
« Reply #7 on: January 07, 2009, 12:07:14 PM »

Maybe is that, fut the first that I though was about edge clamping.

I solved a similiar problem doing that. Well, I don't remember if it was  GL_CLAMP or  GL_CLAMP_TO_EDGE what I used:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

If it was the other thing, sorry.
Logged
TeaAndBiscuits
Level 0
***


View Profile
« Reply #8 on: January 07, 2009, 12:10:00 PM »

As a quick test the change to GL_NEAREST showed that the lines I have been seeing are unwanted pixel data being blended in.

I agree that the best solution is to make my texture coordinates slightly smaller to avoid this.
Logged
moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #9 on: January 09, 2009, 10:20:40 AM »

I once fixed this problem by "zooming in" on the texture, I mean making the texture borders go beyond the quad. I think I remember that I made the "overflow"less than one texture-pixel-wide, if you see what  mean. So not much of the texture was lost.
Logged

subsystems   subsystems   subsystems
TeaAndBiscuits
Level 0
***


View Profile
« Reply #10 on: January 09, 2009, 10:44:38 AM »

This is something I am thinking about doing. It will waste a few pixels of the texture but will ensure that the graphics look RIGHT and not a little distorted.

Still I may just end up using multiple textures rather then the one super texture. We will see. It is something I will revisit when I return to finalise the rendering of my map.
Logged
J.G. Martins
Level 2
**


AKA anvilfolk


View Profile WWW
« Reply #11 on: January 09, 2009, 10:49:31 AM »

So, just wondering. Does this have to do with the fact that OpenGL expects floats or doubles and the precision isn't good enough to address very exactly the start of the texture? And in that case, wouldn't it be possible to actually draw the texture in such a way that it fits perfectly within representable texel values?

Not too into OpenGL, hence my asking Smiley
Logged

Gold is for the mistress -- silver for the maid --
Copper for the craftsman cunning at his trade.
"Good!" cried the Baron, sitting in his hall,
"But iron, cold iron, is the master of them all."
--- Rudyard Kipling
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #12 on: January 09, 2009, 11:08:18 AM »

No, it's just that linear filtering in general works by anti-aliasing the texture by averaging each texel with its surrounding texels, so even if your texture coordinates encapsulate a certain area within a texture perfectly, the edges of that area will get averaged in with the pixels next to them, which lay outside the UV area.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #13 on: January 09, 2009, 11:13:14 AM »

This is something I am thinking about doing. It will waste a few pixels of the texture but will ensure that the graphics look RIGHT and not a little distorted.
As I said I think you can do it with a value small enough so that you only lose fractions of the border pixels.

Quote
Still I may just end up using multiple textures rather then the one super texture. We will see. It is something I will revisit when I return to finalise the rendering of my map.
I don't think it will change anything to the problem.
Logged

subsystems   subsystems   subsystems
J.G. Martins
Level 2
**


AKA anvilfolk


View Profile WWW
« Reply #14 on: January 09, 2009, 12:02:51 PM »

Ah, thanks toastie, that made perfect sense Smiley
Logged

Gold is for the mistress -- silver for the maid --
Copper for the craftsman cunning at his trade.
"Good!" cried the Baron, sitting in his hall,
"But iron, cold iron, is the master of them all."
--- Rudyard Kipling
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic