Diffrent backgrounds for viewport

Hey guys. Im making an OpenGL project that has the window divided into “four” viewports. I need to change the color of the background on each Viewport (all are divided into quarters like an XY graph). I cant seem to get it, I tired putting Color3f and ClearColor in different places corresponding to the viewport. But I get three of the same color and one white quarter. Can anyone help with this problem?

Check this “10. The Viewport Does Not Clip or Scissor”
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

EDIT : oh I just saw something similar was added on the more updated OpenGL wiki :
multiple viewports

The solution should be here
http://www.opengl.org/sdk/docs/man/xhtml/glScissor.xml

Try to put the two commands before invoke glClear(…)
glScissor(x, y, width, height);
glEnable(GL_SCISSOR_TEST);

Put an eye on the performance impact using GL_SCISSOR_TEST.

Thanks you guys, the quarter backgrounds are definitely changing. Just need to tune it a little. Ill keep you posted. :smiley:

The colors change but every time its one quarter ahead of it self and one doesnt change before i do some action in the window.

Heres the snippet of code for one


            Gl.glScissor(200, 200, 200, 200);
            Gl.glEnable(Gl.GL_SCISSOR_TEST);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
            I_Quarter();
            Gl.glDisable(Gl.GL_SCISSOR_TEST);
            Gl.glEnd();

The code is the same for all of them

and when do you swapbuffers ?
(using a double buffered framebuffer, right ?)

If you’re rendering single buffered, that’s probably not very optimal, or useful long term but a glFlush should help.

If you’re rendering double buffer make sure you do all your viewports then swap.

You are calling glEnd above, if you follow OpenGL API names then that end should only follow a glBegin with vertex dispatch calls inbetween. I suspect you intended a glFinish or glFlush.

Yeah im using glFlush() at the end. I should have posted the whole thing, here it is…

        static void Draw()
        {
            Gl.glLineWidth(2);

            Gl.glScissor(200, 200, 200, 200);
            Gl.glEnable(Gl.GL_SCISSOR_TEST);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
            I_Quarter();
            Gl.glDisable(Gl.GL_SCISSOR_TEST);

            Gl.glScissor(200, 0, 200, 200);
            Gl.glEnable(Gl.GL_SCISSOR_TEST);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
            II_Quarter();
            Gl.glDisable(Gl.GL_SCISSOR_TEST);

            Gl.glScissor(0, 0, 200, 200);
            Gl.glEnable(Gl.GL_SCISSOR_TEST);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
            III_Quarter();
            Gl.glDisable(Gl.GL_SCISSOR_TEST);

            Gl.glScissor(0, 200, 200, 200);
            Gl.glEnable(Gl.GL_SCISSOR_TEST);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            IV_Quarter();
            Gl.glDisable(Gl.GL_SCISSOR_TEST);

            Gl.glFlush();
        }

I took out the glEnd() because it wasn’t logical :stuck_out_tongue: :smiley:

Still nothing, cant seem to figure it out…

Are you drawing at every opportunity (equiv to glutIdleFunc) or are you only drawing when the window receives an event?

glClearColor should be moved before the glClear call.
In this way the clear use the color chosen.