GL settings effecting multiple objects

Started by
5 comments, last by daerom 21 years, 6 months ago
Ok, lets say I do a glColor3f(1, 1, 0); to make some text print out Yellow, but I don''t want it to effect anything else. How would I do that? I tried doing this, but it doesn''t even work on the text in the first place, it actually works on the next thing I render, which happends to be my skybox, wich is now tinted yellow. -Daerom
-Daerom
Advertisement
You have to set the color to what you want before you draw every object

i.e

void DrawObject1() {
glColor3f(0.0f, 1.0f, 0.0f);//sets color to green
//drawing code here
}

void DrawObject2() {
glColor3f(1.0f, 0.0f, 0.0f);//sets color to red
//drawing code here
}
What do you mean ''Someday become a programmer?'' I'm a programmer right now!
Thanks

-Daerom
-Daerom
Have a look at glPushAttrib and glPopAttrib too.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I looked at that glPushAttrib and PopAttrib, but I am a little confused as to what mask to use... could you help me out a little

Thanks

-Daerom
-Daerom
You probably need GL_CURRENT_BIT, which will save/restore (Blue Book p415)

- current RGBA color
- current color index
- current normal vector
- current texture coordinates
- current raster position
- GL_CURRENT_RASTER_POSITION_VALID flag
- RGBA color associated with current raster position
- color index associated with current raster position
- texture coordinates associated with current raster position
- GL_EDGE_FLAG flag

The attribute stack is guaranteed at least 16 levels.
Of course the save/restore operation MAY be expensive if a pipeline flush is needed. Think whether you really need it or if a call to glColor() is enough

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks a bunch...


-Daerom
-Daerom

This topic is closed to new replies.

Advertisement