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.
相关问题
- OpenGL Shaders. Pass array of float
- debugging webgl in chrome
- Difference from eglCreatePbufferSurface and eglCre
- SecurityError for same-origin image texImage2D
- Render 3d Objects into Cameraview
相关文章
- Why is glClear blocking in OpenGLES?
- Writing to then reading from an offscreen FBO on i
- How to get OpenGL version using Javascript?
- Why do I need to define a precision value in webgl
- How to change one texture image of a 3d model(maya
- Issue in passing Egl configured surface to native
- Draw a line over UIViewController
- Why do my three.js examples not load properly?
For the overlaying of the 2D weapon, you can use glOrtho for the camera view.
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.
opengl-tutorial has:
Screenshot:
Code:
Tested on Ubuntu 15.10.
Axis oriented version of this question: https://gamedev.stackexchange.com/questions/35946/how-do-i-implement-camera-axis-aligned-billboards Here we have done a viewpoint oriented billboard.
You create a 3d quad and map the .png-based texture to it. You can make the quad face whatever direction you want, as in the first picture, or make it always facing the camera (like a billboard, mentioned by Svenstaro) as in your second picture. Though, to be fair, I am sure that second picture just blitted the image (with some scaling) directly in the software-created framebuffer (that looks like Wolf3d tech, software rendering).
Take a look at OpenGL Point Sprites:
http://www.informit.com/articles/article.aspx?p=770639&seqNum=7
Especially useful for partical systems but may do the trick for your purposes.
Check this tutorial about billboards. I think you'll find useful. http://www.lighthouse3d.com/opengl/billboarding/