Jump to content
  • Advertisement
Sign in to follow this  
Spacemonkey49

Large difference in output of programs

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!