anyone know why this won't work?

Ok, I can’t figure out why this won’t draw anything. It compiles fine, no errors, but it draws a black screen. If I replace it with a series of plain aux calls, they all draw perfectly, but as soon as I put this for loop in there, it draws a black screen. Anybody got any suggestions?

objects_to_render = world.getGameObjects();

  	for(temp=0; temp < objects_to_render.size(); temp++)
  	{
  		test = objects_to_render[temp]->getObjectType();

  		// render an Asteroid
  		if(test == 1)
  		{
  			// asteroid rendering - do in a bit
  			glPushMatrix();
  			glLoadIdentity();

  			// all setup, get the center and draw a sphere
  			// of size 4

  			// hideous and ugly, but should work
  			glTranslatef((objects_to_render[temp]->getCenter().x), 
  				(objects_to_render[temp]->getCenter().y), 
  				(objects_to_render[temp]->getCenter().z));

  			// set the color and draw the asteroid
  			glColor3f(1.0f, 0.0f, 0.0f);
  			auxSolidSphere(4.0f);

  			glPopMatrix();
  		}

  		// render the Ship
  		else if(test == 4)
  		{
  			// ship rendering - do in a bit
  			glPushMatrix();
  			glLoadIdentity();

  			// move object to it's location
  			// ugly again, but should work
  			glTranslatef((objects_to_render[temp]->getCenter().x),
  				(objects_to_render[temp]->getCenter().y),
  				(objects_to_render[temp]->getCenter().z));

  			// the ship is special in that it can face different
  			// directions. Now we must get it's heading and rotate it
  			angle = arctan((objects_to_render[temp]->getOrientation().i),
  				(objects_to_render[temp]->getOrientation().j));

  			glRotatef(angle, 0.0f, 0.0f, 1.0f);

  			// set the color and draw the ship
  			glColor3f(1.0f, 1.0f, 0.0f);
  			auxSolidCone(2.5f, 10.0f);

  			glPopMatrix();
  		}

  		// render a bullet
  		else if(test == 5)
  		{
  			// bullet rendering - do in a bit
  			glPushMatrix();
  			glLoadIdentity();

  			// move object to it's location
  			glTranslatef((objects_to_render[temp]->getCenter().x),
  				(objects_to_render[temp]->getCenter().y),
  				(objects_to_render[temp]->getCenter().z));

  			// set the color and draw the bullet
  			glColor3f(0.0f, 1.0f, 0.0f);
  			auxSolidSphere(1.0f);

  			glPopMatrix();
  		}
  	}

More of a coding issue then. Probably not OpenGL related. Probably either test is not one of the 3 values 1, 4, 5 or the x, y, z coords returned from your objects are not in view. Make sure your z values are correct especially. If you haven’t messed with gluLookAt then your z coords should be negative. Your z value should be between near and far clip planes from either glOrtho, glFrustum, gluPerspective and remember that all three of those function automatically negate the value passed for near and far(ie pass 10 and it is taken as -10). Could be many more things, but thats all I can think of right now.

Are you sure you want the glLoadIdentitys in there? If you leave them there, they will clear out any “camera” transformations you may have done. If you do want them there and those are the only things being rendered, you could do the glLoadIdentity once at the beginning of the method because when you do the glPopMatrix from each object it will then just get set back to the previous matrix which would be the identity if that’s what you set it at.

I am not sure, but maybe it is how your using glLoadIdentity, try remove it from after you glPushMatrix.

If you have setup a gluLookAt or something else to set your camera position.

Then you call glLoadIdentity erases it every time you draw, so your objects are not draw with the camera view.

It you code to works like this:
set camera view

Save matrix //save camera view
Clear Matrix // Clear camera settings
Draw
Load Matrix // Old data restored from Save matrix and camera settings

[This message has been edited by nexusone (edited 04-03-2003).]

Ok, I’ll keep an eye out on my LoadIdentity calls, though I think the camera might be the problem. Thanks for the help.

The “camera” can’t be the problem because you are clearing out any “camera” transformations you have previously done with those glLoadIdentity calls.

Unless of course you are going against the common advice of doing something other than the perspective or ortho setup in the GL_PROJECTION matrix. (gluLookAt, glTranslate, glRotate, glScale, all should never be done on the projection matrix unless you fully understand how they will mess up certain calculations such as fog and lighting.)

I agree with Deiussum, that the camera is most likely not the problem but would need to see more code.

You can ether post your code here or e-mail me and I will look at it.

Originally posted by Ahrezmendi:
Ok, I’ll keep an eye out on my LoadIdentity calls, though I think the camera might be the problem. Thanks for the help.

What i found strange in the source code ist the objects_to_render.size() call. I may be totally wrong, but objects_to_render seems to be an array of objects to render, so calling objects_to_render.size() calls the size()-function of the first object in the array!? And that seems to be a strange place to store the information, HOW MANY objects are to be rendered. Is it possible that the code within the loop is never ever executed?

If this is not the problem, it still seems weird (at least to me) to store this information there… I would prefer a static member variable of the class, i.e. ObjectsToRender::number.

Originally posted by JanHH:
[b]What i found strange in the source code ist the objects_to_render.size() call. I may be totally wrong, but objects_to_render seems to be an array of objects to render, so calling objects_to_render.size() calls the size()-function of the first object in the array!? And that seems to be a strange place to store the information, HOW MANY objects are to be rendered. Is it possible that the code within the loop is never ever executed?

If this is not the problem, it still seems weird (at least to me) to store this information there… I would prefer a static member variable of the class, i.e. ObjectsToRender::number.[/b]

It appears that he is using something like the STL vector class. The objects_to_render is the vector class, where the .size() says how many are in the vector. When you look at where he accesses individual objects, he is accessing them like so. objects_to_render[indexValue].whatever();

The vector class overloads the operator so that you can use it like an array, but it also has methods such as .size().

If it was an actual array like you thought, object_to_render.size() would be a syntax error, not calling size() on the first object. object_to_render would be a pointer to the first object, so it would have to be object_to_render->size() in order to be calling size() on the first object.