Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering 2D sprites in a 3D world?

How do I render 2D sprites in OpenGL given that I have a png of the sprite? See images as an example of the effect I'd like to achieve. Also I would like to overlay weapons on the screen like the rifle in the bottom image. Does anyone know how I would achieve the two effects? Any help is greatly appreciated.

alt text

alt text

like image 456
Xavier Avatar asked Nov 26 '10 01:11

Xavier


People also ask

How do you make 2d in 3d in unity?

To change modes between 2D or 3D mode: Bring up to the Editor Settings Inspector, via the Edit>Project Settings>Editor menu. Then set Default Behavior Mode to either 2D or 3D.

Can you make 2d sprites in blender?

Sprite 2D add-on can be used to generate 2d sprite animation from 3d animated models, this add-on makes the life of 2d game developers much easier, whether you are creating animated sprites for a side-scroller game, top-down game or isometric game, this add-on makes the process much easier for you.


2 Answers

In 3D terms, this is called a "billboard". A billboard is completely flat 2D plane with a texture on it and it always faces the camera.

See here for a pure OpenGL implementation: http://nehe.gamedev.net/data/articles/article.asp?article=19

Just about any 3D engine should be able to do them by default. Ogre3D can do it, for instance.

like image 95
svenstaro Avatar answered Sep 23 '22 17:09

svenstaro


a) For the first case:

That's not really 2D sprites. Those men seem to be rendered as single quads with a texture with some kind of transparency (either alpha test or alpha blending).

Anyway, even a single quad can still be considered a 3D object, so for such situation you might want to treat it as one: track its translation and rotation and render it in the same way as any other 3D object.

b) For the second case:

If you want the gun (a 2D picture, I pressume) to be rendered in the same place without any perspective transformation, then you can use the same technique one uses for drawing the GUI (etc). Have a look at my post here:

2D overlay on a 3D scene

like image 29
Kos Avatar answered Sep 23 '22 17:09

Kos