color change after glRasterPost

honkFactory
Unregistered
 
Post: #1
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
Quote this message in a reply
honkFactory
Unregistered
 
Post: #2
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:
glColor3f0.6f0.6f1.0f );
glRasterPos2f0.0f,0.0f);
printWord(ot.objectWord[i],  fontDL);
glGetFloatv(GL_CURRENT_RASTER_POSITIONrasterPosition);
glColor3f0.5f1.0f0.5f );
glRasterPos4fvrasterPosition);
printWord(ot.objectWord[i],  fontDL); 
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
1) what's in your display list.
2) what does glGetError() say after each function.
Quote this message in a reply
honkFactory
Unregistered
 
Post: #4
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.

PHP Code:
void printWord(char *wordGLuint fontDL)
{
    
glPushAttribGL_LIST_BIT );       // Pushes The Display List Bits
    
glListBasefontDL 32 );           // Sets The Base Character to 32
    
glCallListsstrlen(word), GL_UNSIGNED_BYTEword );
    
glPopAttrib();   



2) There are no error reported by glGetError()
Quote this message in a reply
kberg
Unregistered
 
Post: #5
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...
Quote this message in a reply
kberg
Unregistered
 
Post: #6
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:
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);
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
I looked at this a little more, it does look like it is broken at first glance:

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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ? Find color value of 'pixel' in color buffer? Elphaba 1 4,370 Jul 22, 2009 01:23 PM
Last Post: Bachus
  Change scroll text using xcode imaumac 3 4,179 Nov 29, 2008 03:53 PM
Last Post: imaumac
  Fullscreen change problem madjerry 5 3,228 Aug 4, 2008 10:22 AM
Last Post: AnotherJake