Raj
Raj

Reputation: 2398

how to set viewport color

I am working on opengl in android. Can some-one let me know how to set the background color for viewport(instead of the entire screen). I have 2 viewport in my application and I would like to set different color for the 2 viewports.

Upvotes: 3

Views: 2694

Answers (2)

Christian Rau
Christian Rau

Reputation: 45948

If glClear affects the whole framebuffer and not only the current viewport (not sure about that), then you might also use the scissor test:

glScissor(x, y, w, h);
glEnable(GL_SCISSOR_TEST);
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);

I'm pretty sure the scissor test influences glClear.

Upvotes: 4

Marc
Marc

Reputation: 116

For each viewport do:

glViewport(0, 0, width, height);
glClearColor(0.0, 0.0, 0.0, 1.0); // adapt this to the color you want
glClear(GL_COLOR_BUFFER_BIT);

Before drawing in it.

Upvotes: 1

Related Questions