PDA

View Full Version : Background color



amstel
03-16-2002, 06:48 PM
Now, my background color has a single one. I want its the color to change from up to fall down or left-right. If I write a tedius code to calculate a position where the color is, and specify one color at one position. If I divide my background into 800x600 point, I have to calculate for 800x600 times,and whole calculation is called again each time the scene is drawn. If anyone has any fuction or algorithm,please help me.

Old GLman
03-16-2002, 07:01 PM
Hi, dont really understand what your saying, but set the background color with glClearColor(1.0f,1.0f,1.0f,1.0f) or whatever color you want. Then when you clear the buffer with glClear it will go to that color.

EDIT: Oh you want to do some sort of gradient color fill? Actually I think I might have done this in one of my old projects. Ill get back to you.

EDIT: No sorry I dont have what I thought I did. It is easy to create a texture of what you want in a paint program, then just load it in and map it to a quad. Size the quad so it fills the screen. There is some .bmp and .tga loading code on nehe.gamedev.net. Note this is one way to do, and it is just from the top of my head. Im sure there are other ways. The advanced coders on this forum may have a better solution. Hope this helps.

Old GLman

[This message has been edited by Old GLman (edited 03-16-2002).]

[This message has been edited by Old GLman (edited 03-16-2002).]

harsman
03-17-2002, 12:33 AM
If you want a linear gradient you can just draw a quad as the background (turn off z-writes first) and use smooth shading to create the gradient.

amstel
03-17-2002, 12:51 AM
Thank for all commend,But I can do it as shown below

glPushMatrix();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(m_dMinX,m_dMaxX,m_dMinY,m_dMaxY);
glViewport(0,0,Wx,Wy);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_QUADS);
glColor3d(0.0,0.0,0.0);
glVertex2d(m_dMinX,m_dMinY);//lower left
glColor3d(0.0,0.0,0.0);
glVertex2d(m_dMaxX,m_dMinY);//lower right
glColor3d(0.0,0.0,1.0);
glVertex2d(m_dMaxX,m_dMaxY);//upper right
glColor3d(0.0,0.0,1.0);
glVertex2d(m_dMinX,m_dMaxY);//upper left
glEnd();

glPopMatrix();

I switch from 3D to 2D and create my background on 2D scene and switch to 3D again for drawing any other object.