PDA

View Full Version : glColor not being used by glBitmap



xvs
07-18-2000, 07:35 PM
Hell,

I'm using glBitmap (via glCallList) to draw text over my 3D scene. I know it's not the most efficient way, but I want my lib to support as many options as possible. The problem is that the text, although prints correctly (characters, positions), always shouws up as black (0, 0, 0), even though I called glColor3f(1, 1, 1) just before glRasterPos.
Any takes ?

Bob
07-19-2000, 09:02 AM
I think glBitmap just copies (maybe with blending) the image directly into the framebuffer. This means that each pixel is copied as it's stored in memory, and does not take care of the currently set color.

DFrey
07-19-2000, 09:27 AM
Here is the code I use when doing that very same thing and the color does come through, I don't know if I did something special to get it working now that I've read what Bob says.




// now draw the characters in a string
glListBase(1);
glColor4f(1.0,1.0,1.0,1.0);
glRasterPos3f(x,y,0.0);
glCallLists(tend, GL_UNSIGNED_BYTE, str);


Could probably speed it up a bit by using glColor4fv but that is a minor detail since bitmap text is not often drawn.

[This message has been edited by DFrey (edited 07-19-2000).]

xvs
07-19-2000, 09:34 AM
My docs say that glBitmap read bits, writes pixels depending on if the bit is set or not, in the current raster color.
Here's my code (with some unicode support):

<CODE>
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0, 0, -1);

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glRasterPos2f(x, y); /* x and y are 0 */

while ((c = ugetc(buf + pos)) != 0) {
pos += ucwidth(c);
if ((!range) &#0124; &#0124; (c < range->start) &#0124; &#0124; (c > range->end)) {
range = find_range(usefont, c); /* search for a suitable character range */

if (!range) {
range = find_range(usefont, (c = '^'));
if (!range)
continue;
}
}
/* draw the character */
c -= range->start;
c += range->list_base;

glCallList(c);
}
glPopMatrix();
</CODE>

The string appears correctly, just not in the right color.

DFrey
07-19-2000, 10:03 AM
Make sure lighting is disabled. It is included in determining the final raster color otherwise. Same goes for texture maps too, make sure textures are disabled (unless you want texture mapped bitmaps). Also ensure blending is disabled (or set to something you specifically want).



[This message has been edited by DFrey (edited 07-19-2000).]

xvs
07-19-2000, 12:16 PM
Cool! It Works!
All I had to do though is bind to texture 0 (= disable texturing ?)
Lighting and blending are still on (and I need them on) and the text gets displayed in the correct color.
Thanks everyone!

ribblem
07-19-2000, 01:30 PM
Ya, that is a common problem (I know I've made it more than once). When using multiple textures remember texture 1 goes though texture0.

Relic
07-19-2000, 11:47 PM
Just for the protocol:
"All I had to do though is bind to texture 0 (= disable texturing ?)"

No, not disabling. A glBindTexture with 0 as parameter switches back to the immediate texture in the given dimension and for the current texture unit.

xvs
07-20-2000, 05:04 AM
> "A glBindTexture with 0 as parameter switches back to the immediate texture in the given dimension and for the current texture unit."

Huh ?

Relic
07-20-2000, 09:54 AM
>>
> "A glBindTexture with 0 as parameter switches back to the immediate texture in the given dimension and for the current texture unit."
Huh ?
<<

http://www.opengl.org/discussion_boards/ubb/smile.gif

If you don't use texture objects and download a texture, which texture does OpenGL use? If you use a texture object afterwards, how do you switch back to that first non-object texture?
Answer: Issue glBindtexture with a 0 ID. Viola.
And there are multiple of those, one for 1D, 2D, 3D multiplied by the number of texture units you can switch with glActiveTextureARB.

xvs
07-20-2000, 07:51 PM
Oh. I knew that ^_^
Well, something like it anyway http://www.opengl.org/discussion_boards/ubb/smile.gif
Thanks.