| Author |
Message |
< examples ~ Very simple example of Vertex Arrays, VBO's, Point Sprites |
|
memo
|
Posted: Mon Nov 24, 2008 8:08 pm |
|
|
Joined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK |
I've posted some sample code for using Vertex Arrays, VBO's and Point Sprites at
http://www.memo.tv/files/memotv/oF_VA+VBO+PS.zip
its very very basic and is aimed more at showing those who don't know how to use the mentioned things. You can easily get hundreds of thousands of basic particles, if not millions at decent framerates (depending on hardware of course).
You will need to hack ofTexture.cpp to only use GL_TEXTURE_2D...
check testApp::keyPressed to see what keys do what...
|
|
Top
|
|
|
pelintra
|
Posted: Tue Nov 25, 2008 10:39 pm |
|
|
| Joined: Sat Mar 29, 2008 1:05 pmPosts: 265Location: Lisbon, Portugal |
Jesus! never knew my intel graphics card could draw that many particles
thanks for sharing.
Rui
|
|
Top
|
|
|
fazeaction
|
Posted: Wed Nov 26, 2008 12:23 pm |
|
|
| Joined: Wed Nov 26, 2008 12:18 pmPosts: 8 |
Yeah!!! Thanks Memo for this performance information.
|
|
Top
|
|
|
julapy
|
Posted: Fri Apr 24, 2009 3:35 am |
|
|
Joined: Mon Jan 19, 2009 7:02 amPosts: 214Location: sydney |
hi,
im running into error when building this example in 006.
has anyone been able to port it to version 006?
L.
|
|
Top
|
|
|
martignasse
|
Posted: Fri Apr 24, 2009 7:39 pm |
|
|
| Joined: Sun Nov 23, 2008 1:34 pmPosts: 8Location: France |
hi julapy,
i just did it...
basically, you have to add 'texData.' before all calls to ofTexture data members (like tex_t, rendertarget...) in MSATexture.h and MSAImage.h
Hope it help.
|
|
Top
|
|
|
memo
|
Posted: Wed Apr 29, 2009 8:05 am |
|
|
Joined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK |
yup, for 006 you just need to add texData like martignasse mentioned.
In addition, you don't need to hack ofTexture to always use GL_TEXTURE_2D, but you can do it externally by just calling ofDisableArbTex() once (e.g. in your setup, this disables the use of GL_TEXTURE_RECTANGLE_ARB). After you've loaded the texture you want to use for the point sprite, you can re-enable GL_TEXTURE_RECTANGLE_ARB by calling ofEnableArbTex() if you want to create new textures (e.g. load images etc.) and use rectangular textures for them.
P.S. it will be more optimal to use square power of two textures (e.g. 128x128, 256x256, 512x512, 1024x1024 - if your card supports it).
|
|
Top
|
|
|
vanderlin
|
Posted: Tue May 12, 2009 3:31 am |
|
|
Joined: Sat Jun 02, 2007 6:39 pmPosts: 231 |
This is soo good. Is there away to apply this to a vector of particles?
|
|
Top
|
|
|
memo
|
Posted: Tue May 12, 2009 9:02 am |
|
|
Joined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK |
Yup, when you're cycling through the vector of particles updating them, also write their position and color to arrays to be sent to the card (I think thats what the example is already doing, though with arrays instead of vectors).
|
|
Top
|
|
|
vanderlin
|
Posted: Tue May 12, 2009 2:39 pm |
|
|
Joined: Sat Jun 02, 2007 6:39 pmPosts: 231 |
I guess im kinda confused on how to approach it: If i have a vector of particles like Code: vector <Particle*> particles;
//mouse Click particle.push_back(new Particle(x, y));
//update for(int i=0; i<particles.size(); i++) { particles[i]->update(); }
//draw //eekk you have in your example: Code: glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0]); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 3 * sizeof(float), pos); glVertexPointer(3, GL_FLOAT, 0, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1]); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 4 * sizeof(float), col); glColorPointer(4, GL_FLOAT, 0, 0); How would i get pos and col to be from the particles vector? Do i create a new pos and col array every frame? For numParticles i would just use particles.size(), but im stuck after that.
|
|
Top
|
|
|
memo
|
Posted: Tue May 12, 2009 2:54 pm |
|
|
Joined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK |
ah yea, interesting problem.
I've not encountered this problem cos I generally use a fixed size array of particles, capped to a predetermined maximum size, and whenever I need to add a new particle, I just reset the oldest particle (that way I have control over the maximum number of particles, so system can't grind to a halt under heavy circumstances, and also no object creation or deletion happening every frame).
In your case, you could create a vector for pos and another vector for col as well. Everytime you add or remove a particle, you'd need to add or remove from the pos and col vectors as well. Then you can pass &pos[0] as your position buffer (pointer to the first element in the vector, which stores all data sequentially so you can use it as a normal array).
Maybe there is a better/more efficient way but isn't popping into my head right now.
|
|
Top
|
|
|
chrisoshea
|
Posted: Tue May 12, 2009 3:42 pm |
|
|
| Site AdminJoined: Fri Mar 02, 2007 9:06 amPosts: 444Location: London |
This is an issue I was also having recently.
Adding and removing from a vectors for particles gets very slow when you get to large numbers of particles, so you should use a fixed size array for your particles.
i.e. have MAX_PARTICLES and NUM_PARTICLES
like memo said, knowing which index in the array to use is the trouble. I have a list of particles that are alive, and when adding new particles look up an index to use from the list of particles that are dead.
Also when you loop through to update the arrays for the vbo, you need to loop through the number of alive particles, and not the maximum number of particles, which is where my list of alive particles comes in.
|
|
Top
|
|
|
johnavila2
|
Posted: Tue Jun 09, 2009 2:55 pm |
|
|
| Joined: Tue Feb 24, 2009 5:47 pmPosts: 123 |
Hi Of People If anyone need here is the modified MSATEXURE for 0.06 only download MEMO Version and copy and replace this file  .....  Thx Memo Nice Applications
Attachments:
File comment: MSATEXTURE FOR 0.06
MSATexture.rar [1.11 KiB]
Downloaded 221 times
|
|
Top
|
|
|
potter3366
|
Posted: Tue Jun 09, 2009 9:33 pm |
|
|
| Joined: Thu Jul 03, 2008 7:15 amPosts: 30 |
I have tried to build oF_VA+VBO+PS.zip with modified MSATexture.h, but unsuccessfully  I'm on Windows XP, Visual Studio C++ 2008, of_preRelease_v0.06_windows_VS2008_FAT Can someone tell me what I'm doing wrong... Solution file is in attachment. Compiling... main.cpp d:\radni\openframeworks\of_prerelease_v0.06_windows_vs2008_fat\addons\ofaddons.h(1) : fatal error C1021: invalid preprocessor command 'warning' testApp.cpp d:\radni\openframeworks\of_prerelease_v0.06_windows_vs2008_fat\addons\ofaddons.h(1) : fatal error C1021: invalid preprocessor command 'warning' : particle - 2 error(s), 0 warning(s) Thanx! Mladen
Attachments:
particle.rar [14.21 KiB]
Downloaded 122 times
|
|
Top
|
|
|
johnavila2
|
Posted: Wed Jun 10, 2009 9:15 pm |
|
|
| Joined: Tue Feb 24, 2009 5:47 pmPosts: 123 |
Quote: I have tried to build oF_VA+VBO+PS.zip with modified MSATexture.h, but unsuccessfully
I'm on Windows XP, Visual Studio C++ 2008, of_preRelease_v0.06_windows_VS2008_FAT
Can someone tell me what I'm doing wrong...
Solution file is in attachment.
Compiling... main.cpp d:\radni\openframeworks\of_prerelease_v0.06_windows_vs2008_fat\addons\ofaddons.h(1) : fatal error C1021: invalid preprocessor command 'warning' testApp.cpp d:\radni\openframeworks\of_prerelease_v0.06_windows_vs2008_fat\addons\ofaddons.h(1) : fatal error C1021: invalid preprocessor command 'warning' : particle - 2 error(s), 0 warning(s)
Thanx! Mladen
Hi Potter3366 i download your file but all its ok, i see your error and maybe you maybe not foloww the correct process... Copy the alladdonfiles Projects to the folder apps/addonsExamples and change to name, and copy and paste the files Main.cpp, TespApp.cpp, TestApp.h, MSAImage.h, MSATexture.h, in src folder like your example, and add by hand to the project in visual Studio, and look if you can see the files in your branch folder.. and run... If not solution your problem adviceme and i install visual in my house because muy compnay only works in codebloks.... Have Fun and Take care John Avila
|
|
Top
|
|
|
julapy
|
Posted: Fri Jun 26, 2009 3:38 am |
|
|
Joined: Mon Jan 19, 2009 7:02 amPosts: 214Location: sydney |
im trying to draw ribbon trails using VBO. my ribbon trail vertex array and colour array is like this,
float tvr[ MAX_PARTICLES ][ 6 * MAX_TRAIL_LENGTH ]; // trail vertex. float tcl[ MAX_PARTICLES ][ 4 * MAX_TRAIL_LENGTH ]; // trail colour.
so each particle has a ribbon trail of MAX_TRAIL_LENGTH with two vertex for each point on the ribbon.
currently im drawing using glBegin( GL_QUAD_STRIP ) although would like to optimise using VBOs.
with this point sprite example, im assuming its just grabbing every 2 vertex in the vertex array and using them as the location to draw the point sprite.
do i have to use a VBO for each trail? or is there a way i can pass in my trail vertex and colour arrays into to VBO to render all at once?
|
|
Top
|
|
|
|