PDA

View Full Version : bitmaped labels on a curved surface?



Roach
03-04-2003, 04:42 AM
Hi guys,
Small problem here. I am trying to put labels on a gluSphere. The I create a bitmap display list as Nehe does in his bitmap lesson and use glRasterPos to set where the label should begin to draw.
The problem here is that when I rotate the sphere, the labels (especially the tail end of the labels) curve into the sphere. Because the labels are created dynamically on a one second update, I cannot afford the performance hit of texturing these lables onto the sphere.
I have two possible fixs, both of which I really don't like.

Option 1: Give the labels a Z offset so that the labels are totially visible, the only problem with this is that the labels "float" a little too much above the sphere for my (and my bosses) likeing?

Option 2: For each letter in the label, do an indivigual raster position so that the labels are all on the same plane. This would probibly work, but it a pain in the @ss, as I would need the font width, etc.

Anouther option, that I have tried was to do the labels in an ortho projection. The problem here is that that the labels did not rotate with the sphere, and I really need it to do that.

Any suggestions?

Thanks
Roach

Rommel
03-05-2003, 04:43 PM
There shouldn't really be much of a performance hit associated with texturing the labels at all -- you should just be able to render them to a texture, then texture the sphere with that. At one update per second, that should be very, very little cost -- especially seeing as the data never needs to leave VRAM.

delsydsoft
03-06-2003, 01:16 AM
When you say that you gave the labels a z-offset, did you do it by altering the z-coordinates of the label, or did you use glPolygonOffset?

I do something very similar in my game using glPolygonOffset, and I don't see a floating problem, since PolygonOffset just affects the Z-buffer during rendering.If you haven't tried it, give it a shot.

Roach
03-11-2003, 07:06 AM
I've tried both adding an offset and using glPolygonOffset. I'm not quite sure how to make glPolygon offset work correctly, here is what I am doing though:




void draw()
{
// do regular setting up stuff, enableing depth buffer, etc.

glPolygonOffset(1.0, 1.0);
glPolygonMode(GL_FRONT, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);

// Draw the sphere - i.e. our Globe
glCallList(globeDisplayList_);

glDisable(GL_POLYGON_OFFSET);

// draw the label stuff!
drawLabels();
}

void drawLabels()
{
glPushMatrix();
glPolygonMode(GL_FRONT, GL_POINT);
glEnable(GL_POLYGON_OFFSET_POINT);

// print the text at some lat, long location on the globe
glRasterPos3dv(lat, lon, height);

// print out the string
glListBase(FONT_LIST_BASE);
glCallLists(os.str().length(), GL_UNSIGNED_BYTE, os.str().length());
glDisable(GL_POLYGON_OFFSET_POINT)
glPopMatrix();
}



Any suggestions??

Thanks
Roach

Roach
03-13-2003, 04:42 AM
Hi gang, I'm still having problems with this, any ideas?
Roach

JustHanging
03-13-2003, 04:55 AM
Yeah, don't use depth buffer! Sort your labels and spheres by depth and draw them back to front.

-Ilkka

Roach
03-17-2003, 05:40 AM
Yeah,
Turning off the depth buffer fixed one problem, but created anouther. I can now see the labels everywhere, and they now don't carve into the globe. But when I rotate the globe, the labels on the back face are still visable - when they should be culled.

Any more ideas?? Am I doing something wrong with polygon offset??

roach

JustHanging
03-18-2003, 12:13 AM
When you're drawing without the depth buffer, you have to draw everything back-to front. That is, first draw the labels behind the sphere, then the sphere (with GL_CULL_FACE enabled so backfaces don't show through) and then the labels in front of the sphere.

-Ilkka

Roach
03-18-2003, 05:58 AM
That's what I was afraid of - since I can rotate the sphere, I really don't know from one point to the next what labels will be in front, and which will be in back.

Thanks
Roach

JustHanging
03-18-2003, 08:08 AM
But you can just multiply each position with the modelview matrix it's drawn under (get it by glGetFloatv), then you'll have the eyespace depths in the z component of the resulting vector. Then sort by those.

Another thing you could do is to first draw the sphere with depth testing enabled, find the labels' screen coordinates by gluUnproject, then read the depth buffer value at those position, and determine which labels are drawn (those whose winz<=depth buffer value). Then draw these labels with depth testing disabled.

-Ilkka