Archived

This topic is now archived and is closed to further replies.

Displaying bitmaps NOT using textured quads

This topic is 5946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to display bitmaps, but all the info I find on doing it says to use either textured quads or glDrawPixels(). I don''t like textured quads be it requires that all bitmaps have sizes in powers of 2 (I think) and I head that glDrawPixels is slow (true?). So if YOU were writing a 2D game in OpenGl what would YOU do? Jason Mickela ICQ : 873518 E-Mail: jmickela@pacbell.net ------------------------------ "Evil attacks from all sides but the greatest evil attacks from within." Me ------------------------------

Share this post


Link to post
Share on other sites
example
create a 256x128 sized texture

draw a 200x100 sized image in the bottom left corner

glBegin( GL_QUADS)
glTexCoord(0,0) glVertex3fv(corner1);
glTexCoord(0,100.0/128.0) glVertex3fv(corner2);
glTexCoord(200.0/256.0,100.0/128.0) glVertex3fv(corner3);
glTexCoord(200.0/256.0,0) glVertex3fv(corner4);
glEnd();

get the idea?

Share this post


Link to post
Share on other sites
Hi,
I believe OpenGL has a function to display just standard bitmaps, but I''m not sure how it works...
However, the Windows API has a function to display a bitmap...BitBlt ;-) However, that''s really slow.

I would use textured quads in a 2D game...Powers of 2 texture sizes isn''t much of a restriction. If you don''t have images that are powers of 2, simply resize the image''s canvas and don''t use the blank space...
I think I explained that clear enough... ^-^

--nairb

Share this post


Link to post
Share on other sites
Yes, glDrawPixels is generally slow (on consumer PC hardware, on old SGI systems it was pretty speedy).

The best way to do it is to use textured quads. The best way to use textured quads is to write a bitmap manager that will take care of the details once and reuse this all over.
Some of the things the bitmap manager can do, if it is designed and programmed well:

Load multiple smaller sprites onto single larger power-of-2 textures (sort of like sprite managers that load multiple sprites onto one big DirectDraw surface). This helps reduce video memory wastage. Then you can use the texture matrix and uv mapping to only display part of the larger texture on specific quads.

Handle very large bitmaps by splitting them up into multiple textures. The bitmap manager should always heed the maximum texture size for the current card (which can be as little as 256 for 3dfx cards). If the bitmap is too large for one texture, it should split the bitmap into N textures and then either use a multitexture/multipass method on a single quad the size of the bitmap, or (usually the better choice) draw multiple quads, each mapped with part of the large bitmap.



Anyway, that's what I would do. All in all I agree that its quite silly that there isn't a better/faster OpenGL 2D interface. D3D/DD do a pretty decent job of working together (or did, before Microsoft dropped DD in DX8). There's slowdown involved because of stalls when doing 2D operations, but its nowhere near the insanely slow performance that is common when using the OpenGL glDrawPixels interface.


Edited by - gmcbay on August 8, 2001 1:00:42 PM

Share this post


Link to post
Share on other sites
yes they do
gluBuildMipMaps(..) calls gluScaleImage which resizes your image to powers of 2.
note with geforces + perhaps other new cards ''radeon?'' u can use non power ofd2 sized images but there are restrictions eg no mipmaps (though for a 2d game this aint important)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why don''t you want to use "powers of 2" sprites? It may simplify collision detection...

It is a bit strange, but PC hardware is faster with 3D than 2D...

Share this post


Link to post
Share on other sites
If you''re writing a "2D" game it''s going to be 3D anyway, as far as the hardware is concerned. You''re just going to be texturing flat quads in 3d space.

Do you ever watch the History channel, where the camera pans across an old photograph or something? SURPRISE! That photograph is actually a real life 3d object displayed as a 2d image on the television. Same concept.

Share this post


Link to post
Share on other sites
I guess I''ll help you out a bit...

Here''s a technique that will draw any size sprite on an opengl screen.

1) Determine the size of the sprite. (30pixels x 40pixels)
2) Find the closest ^2 that the sprite will fit into. for the 30x40 example it would be 32x64.
3) Make a texture the size of the ^2(32x64) and paint the sprite(30x40) onto the corner.
4) Draw a quad with the texture, but the the texture coordanites set correctly.

You can also use one giant 1024x1024 texture with all your sprites on it and use the appropriate texture coordanites.

You''d really be better of using an API that will allow you direct access to blitting and pixels like DirectDraw, or if your using LINUX or another real OS Allegro or SDL.

The only reason you should stick to opengl is if your going to be doing heavy alpha blending or antialiasing or rotations.

Share this post


Link to post
Share on other sites