multiple viewports

Hi,

I’m trying to make multiple viewports in a test app to see how much work it’s going to take to make my real app do this. I’n this example, I’ve just split the screen in two and trying to get the background to draw a different color so I know what the viewports look like but it’s not working. My entire screen always ends up one color. Am I not doing something right, I was trying to follow the nehe tutorial?

This is an update entry, I can get each view to draw, but only if it’s the last view in my loop that get’s drawn. So I’d comment out each view and just work on one to make sure that that view shows properly, then when I run them all together, it’s just the last one that draws.


	public void display(GLAutoDrawable drawable) {
		GL gl = drawable.getGL();
		
		this.glDrawable = drawable;
		
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		
		for (int i = 0; i < 2; i++) {

			if (i == 0) {
				gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
				gl.glViewport(0, 0, (int) winWidth / 2, (int) winHeight);
				gl.glMatrixMode(GL.GL_PROJECTION);
				gl.glLoadIdentity ();
				//gl.glOrtho(0, winWidth / 2, winHeight / 2, winHeight / 2, 100, -100);
			}
			else if (i == 1) {
				gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
				gl.glViewport((int) winWidth / 2, 0, (int) winWidth / 2, (int) winHeight);
				gl.glMatrixMode(GL.GL_PROJECTION);
				gl.glLoadIdentity ();
				//gl.glOrtho(0, winWidth / 2, winHeight / 2, winHeight / 2, 100, -100);
			}

			gl.glMatrixMode (GL.GL_MODELVIEW);
			gl.glLoadIdentity ();
			gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
		}
	}

I’m pretty sure that glClear() clears the entire buffer contents, regardless of what projection or viewport you’ve set up. Therefore, to achieve what you want, for each viewport you need to draw a GL_QUAD or similar in order to “clear” the background.
http://opengl.org/sdk/docs/man/xhtml/glClear.xml

Do a search for glScissor and glEnable(GL_SCISSOR_TEST).

I assign a unique color to each element (a triangle mesh) of my model so that when my mouse hovers over the element, I can do a read pixel and do individual element selection this way which is much faster than doing picking, especially since I have so many elements on my canvas.

for each frame display()
drawElements filled w/ unique colors
readPixel to see where mouse is
clear
redrawElements as normal
draw mouse over colors
end of frame display()

Now that I’m adding multiple viewports, the problem is that I have a glClear executed after I’ve ready my mouse over pixel and before I redraw my elements as normal.

So I’m wondering what I need to do so that I don’t clear the entire screen (cause if I take the glClear out, I can see my drawings in each viewport fine, but of course breaks my current functionality).

Is that what glScissor and glEnable(GL_SCISSOR_TEST) will do for me?

[quote=“Wizumwalt,post:4,topic:30274”]
Ummm, ok, nm, think that’s what I should be looking at. Thanks.