Sign in to follow this  

gradient background

This topic is 4220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody, I am trying to make a gradient background for a 3D view, using smooth blending. I try to make the upper points with a color, and bottom points with another one. //... do some initialization and 3D drawing // clear the color and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); glPushMatrix(); // switch to projection mode glMatrixMode(GL_PROJECTION); // save previous matrix which contains the //settings for the perspective projection glPushMatrix(); // reset matrix glLoadIdentity(); // set a 2D orthographic projection gluOrtho2D(0, width, 0, height); // invert the y axis, down is positive glScalef(1, -1, 1); // mover the origin from the bottom left corner // to the upper left corner glTranslatef(0, -height, 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); float curcol[3]; glGetFloatv(GL_CURRENT_COLOR,curcol); // glColor3f(1.0, 0.0, 0.0); glGetFloatv(GL_CURRENT_COLOR,curcol); glBegin(GL_QUADS); glColor3i(1,0,0); glVertex2i(0,0); glVertex2i(0,height); glColor3i(0,1,0); glVertex2i(width,height); glVertex2i(width,0); glEnd(); glGetFloatv(GL_CURRENT_COLOR,curcol); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); /////////////////////////// The problem is that the color never changes. For examples if the last color i was using when doing the 3D drawing was blue. I get the background as a blue rectangle ( although i am using different colors to draw it). As you u see in the code i am using glGetFloatv(GL_CURRENT_COLOR,curcol); to make sure that the color really changes. Thanx in advance

Share this post


Link to post
Share on other sites
Hi lc_overlord;

Thanx for replying. I already tried the glColor3f thing, and it didn't work. As you see in my code i use
glGetFloatv(GL_CURRENT_COLOR,curcol);
to make sure the current color has changed to the value that i want, and although i find it changed the rectangle is drawn with the last color used before this code segment start being executed.
Thanx anyway

Share this post


Link to post
Share on other sites
Try (as per lc_overlord's suggestion):


glDisable(GL_LIGHTING);

glBegin(GL_QUADS);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex2i(0,0);
glVertex2i(0,height);

glColor3f(0.0f, 1.0f, 0.0f);
glVertex2i(width,height);
glVertex2i(width,0);

glEnd();




Cheers,
- llvllatrix

Share this post


Link to post
Share on other sites

This topic is 4220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this