PDA

View Full Version : How to render gradient background?



kangarooxy
10-22-2003, 09:26 PM
Dear all,

I want to render a background with gradient colors, say from green to white, but I don't know how, any hints or suggestions?

Thanks.

blaine
10-22-2003, 10:25 PM
A simple quad, with 2 color parameters, should be enough.

kangarooxy
10-27-2003, 09:51 PM
This works, however this quad rotates as I manipulate the scence with mouse, as is not expected; and also, some of lines I render are not visible after using this code. Any hints?

[This message has been edited by kangarooxy (edited 10-27-2003).]

Relic
10-28-2003, 01:01 AM
The background drawing needs its own modelview projection matrix.
Disable depth test for the background.

Easiest code (not tested):
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST); // Color buffer only rendering
glBegin(GL_QUADS);
glColor3fv(bottomColor);
glVertex2f(-1.0f, -1.0f);
glVertex2f( 1.0f, -1.0f);
glColor3fv(topColor);
glVertex2f( 1.0f, 1.0f);
glVertex2f(-1.0f, 1.0f);
glEnd();
...
// Put your other code which sets up its own projection and modelview matrices here.
// Don't forget to clear the depth buffer.