Large difference in output of programs

Started by
3 comments, last by Spacemonkey49 14 years, 6 months ago
I appear to have a recurring problem, with my program outputs as compared to the outputs resulted form the OpenGL Super Bible outputs. For example one of his programs generates "randomly" placed spheres with a Torus in the middle of the viewpoint and a sphere rotating around the Torus. Mine only displays the Torus with the sphere rotating around it but not the "randomly" placed spheres. I've isolated the problem to the function SetupRC() which in his code example is as follows:

void SetupRC()
    {
    int iSphere;
    
    // Bluish background
    glClearColor(0.0f, 0.0f, .50f, 1.0f );
         
    // Draw everything as wire frame
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
    // Randomly place the sphere inhabitants
    for(iSphere = 0; iSphere < NUM_SPHERES; iSphere++)
        {
        // Pick a random location between -20 and 20 at .1 increments
        float x = ((float)((rand() % 400) - 200) * 0.1f);
        float z = (float)((rand() % 400) - 200) * 0.1f;
        spheres[iSphere].SetOrigin(x, 0.0f, z);
        }
    }
where as in mine it is as follows:

void SetupRC()
{
	int iSphere;

	//Blue-ish background
	glClearColor(0.0f, 0.0f, .50f, 1.0f);

	//Draw everything as wireframe
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	//randomly place there spheres
	for(iSphere = 0; iSphere < NUM_SPHERES; iSphere++);
	{
		float x = ((float)((rand() % 400) - 200) * 0.1f);
		float z = (float)((rand() % 400) - 200) * 0.1f;
		spheres[iSphere].SetOrigin(x, 0.0f, z);
	}
}
The rest of my program is identical to his and these functions too seem identical yet when I copy his function into my program the spheres are generated but when I use my function (which seems identical to his) the spheres are not generated. Could anyone please provide me with some insight as to why this is the case? [Edited by - ApochPiQ on October 24, 2009 9:13:08 AM]
Advertisement
for(iSphere = 0; iSphere < NUM_SPHERES; iSphere++); <--- ;?
you have a ';' after the for loop

so it's a loop doing nothing

:)
Antheus beat me :D

In general if a variable is needed only inside a for loop, it's better to write

for(int i = 0; i<something; i++)

With such a for loop, an error like the one you are experiencing is immediately reported at compile time. ;)
Wow I am a tard, thanks :P

This topic is closed to new replies.

Advertisement