clipping 2d-sprites in OpenGL??

Started by
9 comments, last by Out of Sync 21 years, 12 months ago
the texture images in opengl must be a power of 2, right? i use textures and quads. when my sprite is 20x10, how do i clip it? i can draw it in my paint program to the upper left, and remain the rest black. when the image is 32x32 in size, how can i clip it, when the real image has 20x10??? sorry for my english
Advertisement
You dont clip it, you dont have to
---Quite soon...ICQ: 163187735
I think he''s referring to making the non-image area transparent. If that''s what you want to do, you can do stuff like alpha testing but I recommend just using 32-bit TGAs because they have an alpha channel. This way you can alpha blend images instead of just making unwanted areas transparent. You''ll have to specify the alpha channel with a program like Photoshop though.
or set your texture coordinates to such that it only uses the area 20x10 mapped to the verties
sorry, it was my fault. i dont want clipping!
i mean collision detection for laserhits or so.
Well collisions are something different ;-)

There are 3 options:

1) Checking the bounding boxes of your quads

2) Doing #1, but also checking if overlaping pixels are not transparent (basicaly) - never saw anyone actualy do this in GL

3) Defining regions of a sprite that work for collision detection. This is not so difficult to implement as it sounds.
---Quite soon...ICQ: 163187735
i think about this, but i can not keep in mind how big
any sprite is. there must be powers of 2. and the sprite is
smaller than the texture!
so the image is actually bigger than the sprite,
is this calculated at runtime, or must i know every
sprite size??
Check colision of your quads...

If your texture has a size of 32x32, but the image data is only 20x10. Using u, v coords you are mapping only that small 20x10 region of the image to the quad. So then you just test wether 2 quads have colided.

Now if you want to get more detailed colision then just a bounding box, I dunno Maybe define smaller extra quads that make sort of the shape of your sprite.
thank you ansi2000, that sounds good to me!
but can you tell me how i map a part of the texture to
a smaller quad? how can i do it without scaling the image??
20x10 on a 32x16 sized texture
normally u use texture coordinates of (0,0)-(1,1)
instead use (0,0)-(20.0/32.0,10.0/16.0)
simple aye

http://uk.geocities.com/sloppyturds/gotterdammerung.html

This topic is closed to new replies.

Advertisement