Archived

This topic is now archived and is closed to further replies.

Scope in OpenGL?

This topic is 5851 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

Hi there, Never tried, but just wondering : can I use scope in OpenGL? Like :
  
glRotatef(rotation-rate,x,y,z);
glBegin(GL_TRIANGLES);
	glrotatef(rotation-rate,x,y,z);
	glBegin(GL_TRIANGLES);
		//object no. 1

	glEnd();

	glrotatef(rotation-rate,x,y,z);
	glBegin(GL_TRIANGLES);
		//object no. 2

	glEnd();
glEnd();
  
Okay, I know this code probably won''t work (cause of GL_TRIANGLES), but it''s just for the idea. Making 2 objects, rotate each of them separately, and then rotate both of the objects as if they where one object. Are such things possible? Thanks!

Share this post


Link to post
Share on other sites
You can kind of do what you want (if I understand) like this:
  
glRotatef(FirstVal,x,y,z);
glPushMatrix();
glRotatef(SecondVal,x,y,z);
glBegin(GL_TRIANGLES);
// ...

glEnd();
glPopMatrix();
glPushMatrix();
glRotatef(ThirdVal,x,y,z);
glBegin(GL_TRIANGLES);
// ...

glEnd();
glPopMatrix();


[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
No, because you can only use a subset of OpenGL commands between glBegin and glEnd. You can have OpenGL "remember" previous states (though not for the drawing mode as in your example), using the glPush* and glPop* commands. This is particularly useful for matrices.

Share this post


Link to post
Share on other sites