🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
gradient background
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
ok first, disable lighting, lighting on a background is a bad thing.
second, glColor3i(1,0,0); is not red it's black, try usingl glColor3f instead
second, glColor3i(1,0,0); is not red it's black, try usingl glColor3f instead
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
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
Try (as per lc_overlord's suggestion):
Cheers,
- llvllatrix
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement