libraries for 2D using 3D

Started by
66 comments, last by Kylotan 19 years, 11 months ago
I was reading through the Isometric forum and it occured to me that one of the main problems affecting people using 2D is that they don''t have access to a lot of the cool lighting acceleration that 3D programmers take for granted. The main feature that people seem to need this for is day/night transitions, but it could also apply to 101 other game concepts, such as moving light sources (carrying a torch down a tunnel). As a result, they have to either use palette switching, which restricts them to 256 colours, or learn a 3D api, which takes a lot of time and trouble (in my opinion, anyway), or perhaps use the gamma ramps which will work well for the day/night but not so well for individual lights. My first thought was - isn''t there some sort of library that will let you initialise D3D or OpenGL, and then later render an alpha-blended primitive to the screen to give the impression of night-time, while still allowing you to use DirectDraw or SDL or whatever for 2D graphics? I figured that was probably unreasonable as the library wouldn''t know exactly where in video memory the frame buffer is stored. So my second thought was - is there a simple library that will initialise a 3D API for you to some sane (although not necessarily optimal) settings, and expose a simple API for things like alphablended blits, simple light sources, and so on? I''m sure I recall seeing one once, but that was quite a while ago. And before anyone say so, I don''t consider D3DX or SDL-with-OpenGL to be anything like as simple as I mean SDL using the glSDL back-end may be a start, however. And if there isn''t a decent library of this nature anywhere, would it be worth developing one? [ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
Advertisement
I''m in the process of adding an optional OpenGL renderer to a 2D open-source game, and it might have been nice to have a library like you''ve suggested. It turns out that there isn''t a whole lot of code involved; mostly, it''s a matter of managing sprites as textures.

On the other hand, I''m working on this mostly to learn a bit about OpenGL, so I wouldn''t have wanted a library to insulate me from the details.
For most 2D game developers, I expect the Direct3D initialisation code would be horrendous. There''s masses of it, and it''s all ugly. OpenGL was a lot more compact, but is that as likely to work on as many computers? I really don''t know, not being graphically-minded.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
quote:Original post by Kylotan
OpenGL was a lot more compact, but is that as likely to work on as many computers? I really don''t know, not being graphically-minded.


It''s likely to work on even MORE computers than D3D, OpenGL being ported to a zillion platforms already, and D3D not.


2DNow Banner
quote:Original post by Kylotan
For most 2D game developers, I expect the Direct3D initialisation code would be horrendous. There''s masses of it, and it''s all ugly.

um what are you talking about?
  if(FAILED(pd3d = Direct3DCreate8(D3D_SDK_VERSION))){   // Error}D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = FALSE;d3dpp.BackBufferWidth = width;d3dpp.BackBufferHeight = height;d3dpp.BackBufferCount = 1;d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;d3dpp.BackBufferFormat = D3DFMT_R5G6B5;if(FAILED(pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp, &pd3dDevice))){   // No hardware vertex processing, try in software   if(FAILED(pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &pd3dDevice)))    {         // Hardware Driver Failed, or unknown error, switch to reference driver        if(FAILED(pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp, &pd3dDevice)))	{           // Couldnt create device        }    }}  

I wouldnt exactly call that much, And I have also included alot of error checking etc in there, of which you dont need.



CEO Platoon Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
quote:Original post by Kylotan
For most 2D game developers, I expect the Direct3D initialisation code would be horrendous. There''s masses of it, and it''s all ugly.


sigh... and from a moderator, no less...

If you really want to count lines of code (a silly metric IMHO), then perhaps there is more code for D3D, but most of that code is there to give you lots of control.

As far as the original question, D3DXSprite gets you quite far. The 2D in DX8 article outlines a very simple framework that gives you more control. In general a "2D wrapper" for D3D is very thin. As soon as you get into lighting and "effects", you would probably want to scrap the wrapper and deal with D3D directly.

Given the thinness of a 2D D3D wrapper, the idea of using D3D for alpha and DirectDraw for drawing becomes counterproductive because of the overhead associated with switching.

We must move past this "2D API" vs. "3D API" business. It''s a "Graphics API".



Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
for isometric-like games, i think using plain old 2d blitters is a bit outdated. there''s a bunch of effects you can do with a 3d api, like "real" lighting, zooming in and out of the map view, or particle systems for explosions.. and it''s usually much faster... setting up a 3d viewport and projecting triangles to pixel level and then doing your calculations in 2D is not that hard in D3d or openGl..
Going back to the origional topic a 2d engine in a 3d environment that supports lighting- Yes there is definitly a need for a something like this and Yes I think I it would definitly be worth developing. The only thing close that I can think of is CDX-uses ddraw.

So lets list what features would be desirable:

0. Basiic 2d engine features like a scrolling map, sprites, particles...
1. moveable lightsources
2. Zooming in and out on the map
3. Alphablended blits
4. Of course this would all apply to iso, or whatever views

I''ve used a library before (Javanerds GameFrame for Java) and I didn''t like it because it restricted me from using a the oo design that I wanted to. So I would like to see a library that is fully oo and extensible.
i have thought about a 3d api for 2d games quite a bit... ive been using allegro for some time now, and i wish tehre was a simple library that would allow me to make these calls, but using a 3d api such as open GL and D3D.

blit(source bitmap, dest bitmap, pos x, pos y) seems much simpler to me then all that crazy polygon crap with culling and whatever all taht stuff is im not a 3d guy yet

my downfall has definitly been lighting! it makes any game look better (especially 2d ones). and all the lighting i have access to with a 2d library is crappy blending type functions (check every pixel and add/subtract specified amounts to make it appear lit).

i would love to help out with a library that would allow me to do this, becasue ive been tryinbg to find one for a long time/.

some other usefull fiunctions:

blit(), rotate_blit(), lit_blit(), stretch_blit(), blend_blit()
etc.
and possible simplified loading commands and surface creation...


[edited by - sic_nemesis on July 25, 2002 2:17:55 PM]
______________blah
Actually im currently working on a template-based lightweight OpenGL wrapper. It will have other non-opengl game related features like sound and resource-management, and higher-level classes built using the core wrapper to aid common 2d and 3d features. Im not even sure if its classed as a generic engine or a library.

If there is enough demand for it i could release it under the bsd license or something. (when its done, and i have no idea of how long it will be before i produce a workable version im happy with)

This topic is closed to new replies.

Advertisement