Advertisement

Weird Problem (Sound common enough?)

Started by May 22, 2002 05:34 PM
5 comments, last by mmarshall 22 years, 9 months ago
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?
for (int loop=0; loop< numParticles; loop+=1)
Advertisement
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.
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.
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
  
when posting...
<p>
Like this:
<p>
<code>
//This is code
for(int loop=0; loop<numparticules; loop++)
{
// you get the idea
}
</code>
Yah, thanks. I will know better next time.
Advertisement
Or you can just use the ''source'' tags, which will preserve all of the code and keep your formatting (which will make it easier to read, too).

This topic is closed to new replies.

Advertisement