Hi,
I did a couple of NeHe tutorials, but since I'm a zero at using 3D
programs and much better at the drawing board, I'd like to whip together
a little 2D Sprite Engine instead of doing real 3D. I'd love to use
OpenGL for that, but I have a few things I'm not clear about:
1) I thought I'd draw my images on rectangular polygons by making them
textures for the polygon. However, polygons are limited to be powers of
two in size and square ... what's the best way to work around that?
-> make image and polygon square and just fill the unneeded part of the
image with transparent pixels
-> scale image to be square (i.e. stretch it) and map it onto a
non-square polygon, which should give me my original size again
-> make image square, polygon non-square and just map the image onto the
polygon thus that the unneeded part "falls off" the polygon using
glTexCoord()
-> ???
And which of these is faster?
2) What's a good way to do pixel-precise collision testing on the
polygon, *and* on its texture? I'll need to determine both overlapping
of polygons as well as detect clicks in polygons.
3) Is there any good sample code for 2D sprites with OpenGL somewhere?
BTW -- I'm using MacOS X, so samples for MacOS or FreeBSD would be very
cool, but I'm grateful for any generous donations or even just pointers
to a good FM to R.
Thanks & Cheers,
-- M. Uli Kusterer
http://www.zathras.de
|
|
0
|
|
|
|
Reply
|
Uli
|
8/15/2003 12:32:39 AM |
|
In article <0001HW.BB64890C00B036E5F0284600@netnews.comcast.net>,
Derek Ledbetter <derekledbetter@mindspring.com> wrote:
> Actually, they don't have to be square. The width and height can be
> different powers of two.
Ah,
that'll make things considerably easier.
> Also, some cards support the
> GL_EXT_texture_rectangle extension. This lets your texture dimensions
> be non-powers of two.
Thanks, but that would make my code less portable. And I don't think my
measly Rage 128 Mobility has this feature.
> The second method doesn't look to be faster that the others, and the
> image quality will suffer a bit from the resampling, so I wouldn't do
> that.
That's what I thought, but a friend who has some OpenGL experience
suggested it, so I thought I'd verify whether OpenGL has any weird
behaviour that makes this work better.
> The third method fills fewer pixels than the first, so it should
> be faster.
OK, I'll try that. Thanks for the infos.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
|
|
0
|
|
|
|
Reply
|
Uli
|
8/20/2003 7:52:36 PM
|
|
> Derek Ledbetter <derekledbetter@mindspring.com> wrote:
>>Also, some cards support the
>>GL_EXT_texture_rectangle extension. This lets your texture dimensions
>>be non-powers of two.
Uli Kusterer replied:
> Thanks, but that would make my code less portable. And I don't think my
> measly Rage 128 Mobility has this feature.
You can allocate a texture with the next powers-of-two larger than your
desired texture width and height and fill and use just the right
portion. Use glTexImage2D with a null pointer-to-texels, and then
glCopyTexImage2D to fill in the right portion.
You can't use REPEAT mode in this case, and you are using up more
texture memory, but for most things it works just fine.
--
Andy V
|
|
0
|
|
|
|
Reply
|
Andy
|
8/21/2003 4:08:00 AM
|
|
In article <AAX0b.216$m53.32708@petpeeve.ziplink.net>,
Andy V <nobody@nowhere.net> wrote:
> You can allocate a texture with the next powers-of-two larger than your
> desired texture width and height and fill and use just the right
> portion. Use glTexImage2D with a null pointer-to-texels, and then
> glCopyTexImage2D to fill in the right portion.
Andy,
thanks, I'll look into the gl(...)TexImage(...) stuff.
I feel a little bad asking about all this stuff ... does anyone know a
URL where I can find documentation on the various (groups of) OpenGL
APIs? There's got to be some sort of FAQ about this stuff somewhere?
I madly googled for all that stuff, but the best I got were extremely
dry pages that told me about the matrix maths behind the various APIs...
if I wanted to get involved in the mathematics of 3D graphics, I'd be
writing my own 3D rendering code... ;-)
Also, it seems to be pretty hard to find much on 2D. Googles search
patterns always give me mostly 3D stuff. Anybody know any sites that
tell about that? Or, failing that, a book with a decent chapter on 2D
OpenGL?
Thanks in advance,
-- M. Uli Kusterer
http://www.zathras.de
|
|
0
|
|
|
|
Reply
|
Uli
|
8/21/2003 12:38:32 PM
|
|
In article <HM82b.220$m53.33347@petpeeve.ziplink.net>,
Andy V <nobody@nowhere.net> wrote:
> www.opengl.org is a good starting place -- you can get the
> specifications of OpenGL, plus there are at least 3 FAQ resources there,
> including the technical FAQ managed by fungus.
Hmmm... strange, I didn't find anything there the first time round. It
was pretty much only SGI's advertisements ... I'll give it another try.
Maybe a Google limited to opengl.org will bring something up.
> I'm afraid you will have to bite the bullet and become comfortable with
> matrix math. You will need to know this stuff even using OpenGL.
I think I'll be able to avoid it for my 2D stuff right now. I have
simple requirements :-)
> 2D is 3D with a constant Z value -- often 0.0. For that matter, "3D" is
> really "homogeneous" space with a W value of 1.0. You can get away
> without learning about homogeneous coordinates for a while. :-)
Yeah, it's just that a lot of the sample code does very complicated
things which are needed for 3D, but shouldn't be necessary when doing 2D
(not counting that I'm carrying around a useless 3rd coordinate, I'm
fine with that).
Well, I'll manage somehow, thanks.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
|
|
0
|
|
|
|
Reply
|
Uli
|
8/28/2003 3:49:57 PM
|
|
|
4 Replies
135 Views
(page loaded in 0.046 seconds)
Similiar Articles: 2D texture and 3D texture volume rendering - comp.graphics.api ...... can only load size of power of two images > as 2D textures into ... rectangle" allows the arbitrary dimension of the 2d texture ... behaviour - comp.graphics ... 2D texture and ... drawing an image from a texture to screen - comp.graphics.api ...... Texture); glBindTexture(GL_TEXTURE_2D, m ... anyone know how I can load an arbitrary size image into a texture? ... drawing an image from a texture to screen - comp.graphics.api ... Texture memory usage - comp.graphics.api.opengl... HEIGHT, &height ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE ... OpenGL needs to be able to re-upload the texture to the graphics card if the texture ... Warning - Texture data too large for graphics device. Fitting to ...Copper Fitting Dimensions - Where Do I? - comp.cad.solidworks ... Warning - Texture data too large for graphics device. Fitting to max size available. 2D ... Texture size, Tiling, Optimization - comp.graphics.api.opengl ...I then go over the big texture and check a small 2d array, which ... comp.graphics.api.opengl 7082 articles. 14 ... tiles of the source image..for the texture i ... size ... Rotate around arbitrary pivot point... But more... - comp.graphics ...Hi, I have a map (well, a texture) displayed in a 2D image. To place it in ... How to get new coordinates of rotated object - comp.graphics.api ... Rotate around arbitrary ... resize an image using linear or bicubic spline interpolation not ...... or linear interpolation as in glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG ... Texture size GL_MAX_TEXTURE_SIZE - comp.graphics.api.opengl ... resize an image using linear ... Scrolling Background Texture - comp.graphics.api.opengl... to GL_REPEAT (IIRC) glTexParameteri(GL_TEXTURE_2D, GL ... Picture Size vs. Standard Frame size - comp.graphics.apps.paint ... Scrolling Background Texture - comp.graphics ... GL_POINTS & Textures - comp.graphics.api.openglRender points of your desired size into a texture, the ... ;) ) If you were using GL_TEXTURE_2D then it would ... comp.graphics.api.opengl GL_POINTS & Textures - comp.graphics ... write texture to file - comp.graphics.api.opengl... char* szFilename) { glBindTexture(GL_TEXTURE_2D, nID ... BITMAPFILEHEADER)+WidthBytes*Height); //Size in ... volumetric textures - comp.graphics.api.opengl... to create a ... Display arbitrary size 2d image in opengl - Stack OverflowDisplay arbitrary size 2d image in ... Intel on board graphics under Windows supports none-power-of-2 textures. EDIT2 - and even if you don't have arb texture size, then ... Importing 2D graphics as textures - SketchUp Help - GoogleSee the following 'Importing 2D graphics as textures' section for additional information. ... Drag your mouse away from the anchor point to increase the size of the ... 7/10/2012 7:25:04 PM
|