PDA

View Full Version : Diffrent backgrounds for viewport



Edvinauskas
03-03-2010, 04:30 AM
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?

ZbuffeR
03-03-2010, 05:58 AM
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 (http://www.opengl.org/wiki/Viewing_and_Transformations#How_can_I_draw_more_th an_one_view_of_the_same_scene.3F)

glavatar
03-03-2010, 06:21 AM
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.

Edvinauskas
03-03-2010, 06:56 AM
Thanks you guys, the quarter backgrounds are definitely changing. Just need to tune it a little. Ill keep you posted. :D

Edvinauskas
03-03-2010, 07:47 AM
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

ZbuffeR
03-03-2010, 08:04 AM
and when do you swapbuffers ?
(using a double buffered framebuffer, right ?)

dorbie
03-03-2010, 08:08 AM
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.

Edvinauskas
03-03-2010, 08:25 AM
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 :P :D

Edvinauskas
03-03-2010, 10:20 AM
Still nothing, cant seem to figure it out...

Stanley L
03-03-2010, 02:59 PM
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.

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

glavatar
03-04-2010, 06:51 AM
glClearColor should be moved before the glClear call.
In this way the clear use the color chosen.