Weird Problem (Sound common enough?)
I have been trying to write a simple particle engine, and I can’t get my particles to render in a loop. Consider the following code chuck:
for (int loop=0;loop<MAX_PARTICLES;loop++);
{
glColor4f(Particle[loop].r, Particle[loop].g, Particle[loop].b, Particle[loop].a);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex3f(Particle[loop].x-Particle[loop].Size,
Particle[loop].y-Particle[loop].Size,
Particle[loop].z);
glTexCoord2f(1.0f,0.0f);
glVertex3f(Particle[loop].x-Particle[loop].Size,
Particle[loop].y+Particle[loop].Size,
Particle[loop].z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(Particle[loop].x+Particle[loop].Size,
Particle[loop].y+Particle[loop].Size,
Particle[loop].z);
glTexCoord2f(0.0f,1.0f);
glVertex3f(Particle[loop].x+Particle[loop].Size,
Particle[loop].y-Particle[loop].Size,
Particle[loop].z);
glEnd();
}
glColor4f(Particle[0].r,Particle[0].g,Particle[0].b,Particle[0].a);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex3f(Particle[0].x-Particle[0].Size,
Particle[0].y-Particle[0].Size,
Particle[0].z);
glTexCoord2f(1.0f,0.0f);
glVertex3f(Particle[0].x+Particle[0].Size,
Particle[0].y-Particle[0].Size,
Particle[0].z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(Particle[0].x+Particle[0].Size,
Particle[0].y+Particle[0].Size,
Particle[0].z);
glTexCoord2f(0.0f,1.0f);
glVertex3f(Particle[0].x-Particle[0].Size,
Particle[0].y+Particle[0].Size,
Particle[0].z);
glEnd();
The code outside of the for loop, is a copy of what is inside the loop. For some reason, it does not render the triangles inside the for loop. I did not see anything, until I copied the code to outside of the for block. Afterwards, one lone particle is seen on the screen. There are only two differences between the to sections. One: The variable ‘loop’ is changed to the int 0. Two, One works while the other doesn’t. I have not been able to figure it out. Does anybody have any suggestions?
Some how part of my code was cut off in that posting. My full line of code was:
for (int loop=0;loopUsing +=1 rather than ++ did not help any, but as I changed it, I noticed a semicolon at the end of the line! I do not know how many times I have spent much time trying to solve a problem, when the answer was just under my nose! Anyway, thanks for your help.
for (int loop=0;loop
the reason I put +=1 is because it can be very confusing (the fact you changed it from ++ seems to show that. (They do almost exactly the same thing)
for (int loop=0;loopUsing +=1)
is still incorrect though.
for (int loop=0;loopUsing +=1)
is still incorrect though.
May 25, 2002 12:51 AM
You don''t seem to be able to post your code correctly.<br>
My understanding is that the code gets cuts with the message... (the smaller than sign being interpreted as html)<br>
try surrounding your code with HTML
<p>
Like this:
<p>
<code>
//This is code
for(int loop=0; loop<numparticules; loop++)
{
// you get the idea
}
</code>
My understanding is that the code gets cuts with the message... (the smaller than sign being interpreted as html)<br>
try surrounding your code with HTML
when posting...<p>
Like this:
<p>
<code>
//This is code
for(int loop=0; loop<numparticules; loop++)
{
// you get the idea
}
</code>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement