openGL 2d drawing problems, objects appear to overlap

matthew
Unregistered
 
Post: #1
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
What blending function are you using, and how are you drawing it?
Quote this message in a reply
matthew
Unregistered
 
Post: #3
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.

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
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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...
Quote this message in a reply
matthew
Unregistered
 
Post: #6
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 this message in a reply
matthew
Unregistered
 
Post: #7
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..
Quote this message in a reply
matthew
Unregistered
 
Post: #8
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
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #9
Perhaps it was your texture border setting. If you texture with linear filtering you need to be careful about the border. Try clamping.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #10
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
Quote this message in a reply
matthew
Unregistered
 
Post: #11
Quote:Originally posted by kelvin
Code:
--snip--

--snip-- Got it.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
Code:
#define GL_CLAMP_TO_EDGE                  0x812F

note 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...
Quote this message in a reply
matthew
Unregistered
 
Post: #13
I tried _glClampToEdge and it didn't fix anything. I am going to stick with _glLinear for now, using the fix that I mentioned.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Problems jhbau1000 1 5,329 Jul 12, 2010 05:57 AM
Last Post: Kezhaya
  OpenGL ES 2.0 Problems - Senior Project Thread Zammy 3 4,558 Mar 16, 2010 12:32 PM
Last Post: arekkusu
  First Person Objects (Gun) in OpenGL mikey 21 9,626 Jun 3, 2009 11:01 AM
Last Post: mikey
  opengl text/font drawing from CGContext fretmunky 11 13,048 Dec 7, 2008 11:29 AM
Last Post: fretmunky
  OpenGL ES - Drawing a simple cube help. MattCairns 7 12,587 Oct 10, 2008 05:26 PM
Last Post: Frogblast