openGL 2d drawing problems, objects appear to overlap
I have noticed that when I draw objects in openGL, that the alpha seems to move a little to the right.
In the screenshot below, when I draw a screen full of 32x32 squares, a small line is produced as a result of this.
Any assistance would be greatly appreciated. (I read over Carlos' post, I am hoping I posted correctly.)
screenshot
screenshot (a little more clear)
The problem area I am talking about, is the circled area.
Bummer, no avatar for me yet.
In the screenshot below, when I draw a screen full of 32x32 squares, a small line is produced as a result of this.
Any assistance would be greatly appreciated. (I read over Carlos' post, I am hoping I posted correctly.)
screenshot
screenshot (a little more clear)
The problem area I am talking about, is the circled area.
Bummer, no avatar for me yet.
What blending function are you using, and how are you drawing it?
I am using _glBlend for blending.
All sprites are drawn to a rect. The below function converts the rest into information needed to draw to the screen.
All sprites are drawn to a rect. The below function converts the rest into information needed to draw to the screen.
Code:
xSize = (Sprite.toRect.right-Sprite.toRect.left)/2
ySize = (Sprite.toRect.bottom-Sprite.toRect.top)/2
x = xSize+Sprite.toRect.left
y = ySize+Sprite.toRect.top
t1x = Sprite.fromRect.left/gSpriteMap.mapWidth (Sprite.mapId)
t1y = Sprite.fromRect.top/gSpriteMap.mapWidth (Sprite.mapId)
t2x = (Sprite.fromRect.left+(Sprite.fromRect.right-Sprite.fromRect.left))/gSpriteMap.mapWidth (Sprite.mapId)
t2y = (Sprite.fromRect.top+(Sprite.fromRect.bottom-Sprite.fromRect.top))/gSpriteMap.mapWidth (Sprite.mapId)
x = Sprite.toRect.left+xSize
y = Sprite.toRect.top+ySize
I am uncertain on this, but it could either be (a) that stupid OpenGL bug which does not really allow pixel-perfect alignement horizontally, there was a lengthy discussion here and on the Apple OpenGL mailing list, or it could simply be (b) numerical drift.
In case of (b), I have to ask if you are using shared vertices, or does each quad has its own. You should be using shared vertices to avoid any numerical inaccuracy. Though the way that looks is really strange.
In case of (b), I have to ask if you are using shared vertices, or does each quad has its own. You should be using shared vertices to avoid any numerical inaccuracy. Though the way that looks is really strange.
So you haven't changed the blend function with glBlendFunc?
In that case it defaults to GL_ONE, GL_ZERO which may not be what you want...
Are you drawing with quads? triangles? points? lines? what's your point/line size if applicable? are you using antialiased points/lines?
Give me some information here, or I can't hope to guess your problem...
In that case it defaults to GL_ONE, GL_ZERO which may not be what you want...
Are you drawing with quads? triangles? points? lines? what's your point/line size if applicable? are you using antialiased points/lines?
Give me some information here, or I can't hope to guess your problem...
Quote:Originally posted by OneSadCookie
So you haven't changed the blend function with glBlendFunc?
In that case it defaults to GL_ONE, GL_ZERO which may not be what you want...
Are you drawing with quads? triangles? points? lines? what's your point/line size if applicable? are you using antialiased points/lines?
Give me some information here, or I can't hope to guess your problem...
Actually I am using this: glBlendFunc (_glSrcAlpha, _glOneMinusSrcAlpha)
(Sorry, not totally familiar with everything openGL)
I am using GLQuads, after the code posted above, I use the code below:
Code:
glTranslated (x,y,0)
glBegin(_glQuads)
glTexCoord2d(t1x,t1y)
glVertex2d(-xSize, -ySize)
glTexCoord2d(t2x,t1y)
glVertex2d(xSize, -ySize)
glTexCoord2d(t2x,t2y)
glVertex2d(xSize, ySize)
glTexCoord2d(t1x,t2y)
glVertex2d(-xSize, ySize)
glEnd
glTranslated(-x,-y,0)Quote:Originally posted by DoooG
In case of (b), I have to ask if you are using shared vertices, or does each quad has its own. You should be using shared vertices to avoid any numerical inaccuracy. Though the way that looks is really strange.
I do not know what shared vertices are..
I had a friend of mine give me a helping hand, and instead of using _glLinear, I use _glNearest and it fixed the problem.
Another work around was to use t1x = t1x + 0.001
Another work around was to use t1x = t1x + 0.001
Perhaps it was your texture border setting. If you texture with linear filtering you need to be careful about the border. Try clamping.
Code:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Code:
#define GL_CLAMP_TO_EDGE 0x812Fnote it's also known as GL_CLAMP_TO_EDGE_SGIS... you should really check for either OpenGL 1.2 or the GL_SGIS_texture_edge_clamp extension before using it.
Of course, it's supported on all renderers on Mac OS X, so it's not really an issue other than of style...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES Texture Problems | jhbau1000 | 1 | 4,414 |
Jul 12, 2010 05:57 AM Last Post: Kezhaya |
|
| OpenGL ES 2.0 Problems - Senior Project Thread | Zammy | 3 | 3,892 |
Mar 16, 2010 12:32 PM Last Post: arekkusu |
|
| First Person Objects (Gun) in OpenGL | mikey | 21 | 7,669 |
Jun 3, 2009 11:01 AM Last Post: mikey |
|
| opengl text/font drawing from CGContext | fretmunky | 11 | 11,395 |
Dec 7, 2008 11:29 AM Last Post: fretmunky |
|
| OpenGL ES - Drawing a simple cube help. | MattCairns | 7 | 10,978 |
Oct 10, 2008 05:26 PM Last Post: Frogblast |
|

