color change after glRasterPost
Why does a call to glColor() have no effect if it is placed directly after a glRasterPos? I have text stored as display list and I want to be able to have different letters in some text be different colors. However all the calls to glColor after a call to glRasterPos don't change the color. Why is this? Is there any way around this?
thanks
Alex
thanks
Alex
Here is something I tried that did not work. Basic I draw blue text, I try to retrieve current raster postition, I apply a new color and reapply the raster positition and then I print again. What is wrong with this?
PHP Code:
glColor3f( 0.6f, 0.6f, 1.0f );
glRasterPos2f( 0.0f,0.0f);
printWord(ot.objectWord[i], fontDL);
glGetFloatv(GL_CURRENT_RASTER_POSITION, rasterPosition);
glColor3f( 0.5f, 1.0f, 0.5f );
glRasterPos4fv( rasterPosition);
printWord(ot.objectWord[i], fontDL);
1) what's in your display list.
2) what does glGetError() say after each function.
2) what does glGetError() say after each function.
1) I use the same approach to drawing text that is used in NeHe project 13. It works too. The above code will display the text both times I call printWord (see below)and it will do so in the proper color. The problem I am having is that the second time I call printWord is that the text is not were I want it to be: directly after the first string. Remember, what I am trying to do is change the color of the bitmap (have one string of text with different colored characters). To do this I have to recall glRasterPos(). But I cannot get the proper position to pass to glRasterPos(). What I try to do is to get the raster postition with glGetFloatv(GL_CURRENT_RASTER_POSITION, rasterPosition); then, after applying a new color, pass the call glRasterPos(rasterPosition) with the hope that the next display list I draw will be at the end of the text I have already draw.
2) There are no error reported by glGetError()
PHP Code:
void printWord(char *word, GLuint fontDL)
{
glPushAttrib( GL_LIST_BIT ); // Pushes The Display List Bits
glListBase( fontDL - 32 ); // Sets The Base Character to 32
glCallLists( strlen(word), GL_UNSIGNED_BYTE, word );
glPopAttrib();
}
2) There are no error reported by glGetError()
If you make certain calls during the construction of your display list (such as glcolor), when you call those display lists it will overwrite/disable the colour you set in immediate mode prior to calling your printWord function. Seeing how you create your bitmap font display lists would help in figuring out what's going wrong...
In addition, if you have an offset specified in your call to glBitmap when you created your display lists, if all you are trying to do is draw different coloured characters, you shouldn't need any additional calls to glRasterPos as the current raster position should be offset with each character you print...
ie, this should work for bitmap fonts as they are normally generated:
ie, this should work for bitmap fonts as they are normally generated:
Code:
glRasterPos2i(xPos, yPos);
glColor3f(1.0f, 1.0f, 1.0f);
printWord(myText[0], font_list_base);
glColor3f(1.0f, 0.5f, 1.0f);
printWord(myText[1], font_list_base);
glColor3f(0.5f, 1.0f, 1.0f);
printWord(myText[2], font_list_base);
I looked at this a little more, it does look like it is broken at first glance:
Here, the color is not red. It's whatever it was before glRasterPos2f.
Here, the color is correctly set to red.
The explanation for this is found in the man page for glRasterPos-- raster operations maintain their own state for current color and current texture coordinate (e.g. GL_CURRENT_RASTER_COLOR) In this case, with lighting turned off, the state is copied from GL_CURRENT_COLOR *when you call glRasterPos2f*. So glColor4f between that and a raster operation is ignored.
Code:
glRasterPos2f(x, y);
glColor4f(1, 0, 0, 1);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '*');Here, the color is not red. It's whatever it was before glRasterPos2f.
Code:
glColor4f(1, 0, 0, 1);
glRasterPos2f(x, y);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '*')Here, the color is correctly set to red.
The explanation for this is found in the man page for glRasterPos-- raster operations maintain their own state for current color and current texture coordinate (e.g. GL_CURRENT_RASTER_COLOR) In this case, with lighting turned off, the state is copied from GL_CURRENT_COLOR *when you call glRasterPos2f*. So glColor4f between that and a raster operation is ignored.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| ? Find color value of 'pixel' in color buffer? | Elphaba | 1 | 3,511 |
Jul 22, 2009 01:23 PM Last Post: Bachus |
|
| Change scroll text using xcode | imaumac | 3 | 3,727 |
Nov 29, 2008 03:53 PM Last Post: imaumac |
|
| Fullscreen change problem | madjerry | 5 | 2,895 |
Aug 4, 2008 10:22 AM Last Post: AnotherJake |
|

