Codesnippets > 3D-snippets
X_SPRITE replacement - (faster) 3D sprite with rotation (billboards)
Wampus:
Is this faster than drawing sprites using the same sprite sheet (i.e. just one texture) with POLYVECTOR?
Kitty Hello:
This is like POLYVECTOR, but for 3D scenes. Top work! Put sticky.
kanonet:
Was someone able to test this on other graphic cards or mobile devices?
If you dont want to include the hole gl.gbas (cuz its slow to compile), than you can include the following, it contains all opengl calls that are necessary to get it working:
--- Code: (glbasic) ---// OpenGL calls, only use gl.gbas _OR_ the following:
INLINE
#ifdef CENTERLINE_CLPP
#define signed
#endif
#define OGL ::
typedef unsigned int GLenum;
typedef void GLvoid;
typedef int GLint;
typedef int GLsizei;
}
extern "C" {
void __stdcall glEnableClientState( GLenum cap ); /* 1.1 */
void __stdcall glDisableClientState( GLenum cap ); /* 1.1 */
void __stdcall glVertexPointer( GLint size , GLenum typ , GLsizei stride , const GLvoid *ptr );
void __stdcall glNormalPointer( GLenum typ , GLsizei stride , const GLvoid *ptr );
void __stdcall glTexCoordPointer( GLint size , GLenum typ , GLsizei stride , const GLvoid *ptr );
void __stdcall glDrawArrays( GLenum mode , GLint first , GLsizei count );
}
namespace __GLBASIC__ {
ENDINLINE
CONSTANT GL_TRIANGLE_STRIP = 0x0005
CONSTANT GL_FLOAT = 0x1406
CONSTANT GL_DOUBLE = 0x140A
CONSTANT GL_VERTEX_ARRAY = 0x8074
CONSTANT GL_NORMAL_ARRAY = 0x8075
CONSTANT GL_TEXTURE_COORD_ARRAY = 0x8078
FUNCTION glEnableClientState: cap
INLINE
OGL glEnableClientState(cap);
ENDINLINE
ENDFUNCTION
FUNCTION glDisableClientState: cap
INLINE
OGL glDisableClientState(cap);
ENDINLINE
ENDFUNCTION
FUNCTION glVertexPointer: size, typ, stride, ptr[]
typ=GL_DOUBLE;
INLINE
OGL glVertexPointer(size, typ, stride, &ptr(0));
ENDINLINE
ENDFUNCTION
FUNCTION glNormalPointer: typ, stride, ptr[]
typ = GL_DOUBLE;
INLINE
OGL glNormalPointer(typ, stride, &ptr(0));
ENDINLINE
ENDFUNCTION
FUNCTION glTexCoordPointer: size, typ, stride, ptr[]
typ = GL_DOUBLE;
INLINE
OGL glTexCoordPointer(size, typ, stride, &ptr(0));
ENDINLINE
ENDFUNCTION
FUNCTION glDrawArrays: mode, first, count
INLINE
OGL glDrawArrays(mode, first, count);
ENDINLINE
ENDFUNCTION
--- End code ---
Hemlos:
--- Quote ---Now i want someone to create a decent particle engine with this.
--- End quote ---
Its already built, all i need to do it splice it in.
1. Is this much faster than polyvector?
2. Why is there only one rotation? you need at least 2.
3. Is this a "point sprite"?
If no to #3, do you know how to implement them?
Spritez3d would go from thousands of particles to millions overnight.
kanonet:
1. I think you (and maybe Wampus?) got something wrong. Polyvector is for 2D graphic, this code here replaces X_SPRITE, which means its for 3D graphic. So for your 2D SpriteZ stick with Polyvector, but this code could be really useful for a 3D particle engine, because it has everything that X_SPRITE has, plus some extras and way more speed. This is a 3D-Sprite/Billboard, it can be places anywhere in 3D scene and it will always face the camera, no matter where it is. It just shares with polyvectors, that its fast and that you can optimise it with proper texture ordering (like always in 3D, texture ordering is faster than calling X_SETTEXTURE for each object).
2. In 3D scene you have 3 axes, so you need 3 rotations. But this is a billboard, so it autoimatically faces the camera, the hole point in this code is, that it handles the rotation around 2 axes independently, so it always faces the camera, so you dont need to worry about doing this by yourself. So you just need to worry about the 3rd rotation, thats why it is just 1 rotation, like in a 2D scene. Btw this is one of the advantages of this code over X_SPRITE which does not allow you to change this rotation.
3. No this is not a Pointsprite, i render a quad to the scene for each sprite, but i do this way faster, than native GLB could ever do it. A pointsprite is a special GPU feature on more modern graphic cards, so you dont need to render a quad, but just tell the GPU the point where to place the Sprite (its faster). Pointsprites do not work with older graphic hardware and maybe not with mobile platforms, but i dont know in detail how much its supported nowadays. And i dont know how to implement it, was never interested in it, cuz i wanted a solution that run even on old hardware. If you want to get it working, than you will definitely need to use INLINE, and im definitely the wrong person to ask about this, since i have no C skills.
EDIT: i just noticed, that sometimes every billboard is called a point sprite, but in my opinion this is not correct. But if you just mean a billboard, not the special GPU feature for faster billboards, than this is a point sprite, cuz it draws a 2D sprite on a point in 3D world. :D
How do you render your particles in you 3D SpriteZ now? With X_SPRITE or do you draw your own quads/triangles with GLB commands? Anyways, this code here is way faster than both solutions and it works on all PCs with OpenGL 1.1 or higher. I did not try it on a mobile device, since i don have one of them (besides an old Win Mobile phone).
See here for more details: http://nehe.gamedev.net/article/billboarding_how_to/18011/
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version