Displaying hexswirls in four different viewports simultaneously


I am trying to display four different viewport versions of this hexswirl image simultaneously. However, after compiling I can only see the fourth viewport in the lower left corner. I know that the hexswirl function calls the glClear each time and tried to comment out and got some crazy looking image. In reading the other posts on multiple viewports I have come upon glScissors but don’t really know how to use it. If someone could explain how to display all my viewports at the same time I would greatly appreciate it.

Here is the hexswirl code but since I can’t have parenthesis I have deleted them…

void hexswirl
	double angle;                       //the angle of rotation
	double angleInc = 2*3.14159265/6.0; //the angle increment
	double inc = 5.0/100;               //the radius increment
	double radius = 5.0/100.0;          //the radius to be used

	//clear the background

	//draw the hexagon swirl
	for int j = 0; j <= 50; j++
		//the angle of rotation depends on which hexagon is 
		//being drawn.
		angle = j* 3.14159265/180.0;

		//draw one hexagon
		glBegin GL_LINE_STRIP;
			for int k=0; k <= 6; k++
				angle += angleInc;
radius * cosangle radius *sinangle


		//determine the radius of the next hexagon
		radius += inc;
	//swap buffers for a smooth change from one
	//frame to another


Oh yes, here is the rest of the code I used to divide my world window into four viewports…

void myDisplayvoid
     setWindow-5.0, 5.0, -5.0, 5.0; 
     glViewport0, screenHeight/2, screenWidth/2, screenHeight/2;
     setWindow-3.0, 3.0, -3.0, 3.0;
     glViewportscreenWidth/2, screenHeight/2, screenWidth/2, screenHeight/2;
     setWindow-1.5, 1.5, -1.5, 1.5;
     glViewportscreenWidth/2, 0, screenWidth/2, screenHeight/2;
     setWindow-0.1, 0.1, -0.1, 0.1;
     glViewport0, 0, screenWidth/2, screenHeight/2;

Oh yes, does anyone know how to display parenthesis on this site?

You need to move the glClear, glutSwapBuffers, glFlush out of the hexswirl function, so that they dont get called four times.
Call glClear at the start of your display function and call flush and swap at the end of display.

And you can use the code tags when including example code in your post.

Hey Tempocrew,

Thank you very much for your advice. My 4 viewports look great! Also what do you mean by code tags?


Originally posted by 1nuprogrammer:
… what do you mean by code tags?

I have edited your posts to include code tags, you may now edit them to see how that is done and optionally add the correct parenthesis to your code. As you can see, useful information like indentation is preserved.