Public Group

# Opengl 2D Particle System Problems

This topic is 4578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, back again with another problem :P, I havent been programming for awhile so i thought id pick up where i left off, particle systems. I couldnt find a simple particle system tutorial, so i started to make my own. It started off well enough cParticle test( 3 (size), 10 (Particles), (Pos) ); That works Fine, but if i put anymore particles above 10 into it the program will either compile and not run (or maybe for a 1/2 secound), or it does but as a blank screen or as a big red long quad ? Class.h

class cPos
{

public:

int xPos;
int yPos;

cPos operator + ( cPos );
cPos operator + ( int );

cPos() : xPos( 0 ), yPos( 0 )
{}

cPos( int a, int b ) : xPos(a), yPos(b)
{}

};

class cParticle
{

cPos origin;
cPos end;

int maxP;
int size;

public:

void Init( int );
void InitParticles();

void Display();

cParticle( int s, int m, cPos a ) : maxP(m), size(s)
{

origin.xPos = a.xPos;
origin.yPos = a.yPos;

end.xPos = 100;
end.yPos = 100;

InitParticles();

}
};


Class.cpp
cPos cPos::operator + ( cPos c )
{

int a = xPos + c.xPos;
int b = yPos + c.yPos;

return cPos(a,b);
}

cPos cPos::operator + ( int c )
{

int a = xPos + c;
int b = yPos;

return cPos(a,b);
}
///////
void cParticle::Init( int i )
{

Part.setPos( origin + (10*i) );
Part.setSize( size );
Part.alive = true;

}

void cParticle::InitParticles()
{

for( int i = 0; i < maxP; i++ )
{
Init(i);
}
}

void cParticle::Display()
{

cPos End( 0, 0 );
cPos End2( 200, 200 );
cPos End3( 500, 0 );
cPos EndAll( 100, 100 );

for( int i = 0; i < maxP; i++ )
{
Part.Draw();
}

}


Any and all help is greatly apreciated ;)

##### Share on other sites
Well one possible error is your array of cQuads has a set size of 20. You should look into std::vector for a resizable list.

##### Share on other sites
Yea but the thing is that i actually had an array of 100 quads when i first did it, i only put 20 in as an example, and now that im try it again, when i put in 20, nothing displays? :P. Only if i have 10 ... i dont understand the difference in the array size but meh, ill switch to vectors. Thanks ;)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634089
• Total Posts
3015460
×