TeaAndBiscuits
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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!](https://forums.tigsource.com/Smileys/derek/toast.gif)
|
|
|
Logged
|
|
|
|
Ivan
Owl Country
Level 10
alright, let's see what we can see
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
|
|
|
TeaAndBiscuits
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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!](https://forums.tigsource.com/Smileys/derek/toast.gif)
|
|
|
Logged
|
|
|
|
Javilop
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
|
|
|
Javilop
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« Reply #5 on: January 07, 2009, 12:01:51 PM » |
|
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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
|
|
|
Javilop
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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](https://forums.tigsource.com/Smileys/derek/smiley.gif)
|
|
|
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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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
|
|
|
|
moi
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« 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. 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
|
![](https://forums.tigsource.com/Themes/tigsource/images/post/xx.gif) |
« Reply #14 on: January 09, 2009, 12:02:51 PM » |
|
Ah, thanks toastie, that made perfect sense ![Smiley](https://forums.tigsource.com/Smileys/derek/smiley.gif)
|
|
|
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
|
|
|
|