glVertex*f lines not working over a 2D texture


I’ve got some 2D images representing cuts of a 3D volume in a program and I need to make the contour of those 2D images (managed as textures) in order to define the volume.
I use glVertex*f for this purpose but can’t get to see any lines…

Some lines of code :

void init (void) {
glEnable (GL_TEXTURE_2D);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glGenTextures (1, texture_id);
glBindTexture (GL_TEXTURE_2D, texture_id[0]);
load_texture (“test.dcm”);
//Have tried with depth test on and off
//glEnable (GL_DEPTH_TEST);
glClearColor (0.0, 0.0, 0.0, 0.0);

void draw_texture (int number) {
float tempX= -0.5f+panX0+panX, tempY=-0.5f+panY0+panY;
int i;
//change filtering for performance when zooming
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtre);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtre);
glPushMatrix ();
glColor3f (1.0, 1.0, 1.0);
glBindTexture (GL_TEXTURE_2D, texture_id[number]);
glBegin (GL_QUADS); //apply texture (512512)
glTexCoord2f(0.0f, 0.0f); glVertex3f(tempX, tempY, depth_factor);
glTexCoord2f(1.0f, 0.0f); glVertex3f(tempX+1.0F, tempY, depth_factor);
glTexCoord2f(1.0f, 1.0f); glVertex3f(tempX+1.0F, tempY+1.0F, depth_factor);
glTexCoord2f(0.0f, 1.0f); glVertex3f(tempX, tempY+1.0F, depth_factor);
glEnd ();
glColor3f (1.0, 0.0, 0.0);
try to draw the line on top (tried also glVertex3f with any z coordonates
from texture.z-3.0f to texture.z+3.0f without results) */
glBegin (GL_LINE_LOOP);
for (i=0; i<C1.nbr; ++i) //draw the contour
glEnd ();
glPopMatrix ( );

void display ( void ) {
//tried with the depth bit as well
glPushMatrix ();
draw_texture (0);
glPopMatrix ();
glutSwapBuffers ();

void reshape ( int w, int h ) {
glViewport (0, 0, (GLint) w, (GLint) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLdouble)w/ (GLdouble)h, 0.1, 1000.0); //not a special one… enabling to zoom near and far the picture
//glOrtho(0, 256, 256, 0, 0, -10);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

Any help is welcome


What contour do you expect to see ? The contour of the quad (4 lines) or the contour of the image inside the texture ?

The countour of the image inside the picture.

I got an algorithm to get it (array of points to connect) from thresholds defined but can’t get it draw… =/

Et que représente test.dcm ? l’image des contours déjà calculés ou bien une image quelconque sur laquelle les contours doivent être calculés ?

oops please explain my french attitude

and also you should try to render lines without texturing (but quad still textured) while depth test is turned off (it should be on in the long run, but for the test it’s better to disable it).

[This message has been edited by vincoof (edited 03-11-2003).]

En fait c’est un programme de traitement d’images scientifique et test.dcm est une image au format DICOM (scanner, IRM) dont je calcule le contour par après (les points du contour sont dans C1) Ce sont ces points que je veux afficher et relier par dessus l’image DCM ^^

Excuse my french speakin’ attitude too…

Also, have you checked the coordinates of your contour ? Do they range between [tempX,tempX+1]x[tempY,tempY+1] ? Is the quad visible ?

How do I draw lines wihtout textured? Isn’t it already the case (glvertex* is in line_loop mode, not in quads)…

My QUAD is visible when I disable (GL_TEXTURE_2D) and so is the red line too; But once I apply the texture, no line is visible any more. Must I disable the TEXTURE mode before drawing the line? Won’t my texture disappear ?

OK, I’ve done some test

  • with glVertex2f :

It doesn’t work at all (even if disabling GL_TEXTURE_2D)

  • with glVertex3f:

  • When i DO enable (GL_TEXTURE_2D) I see the line but in black (my image is grayscale. Factor?) (texture z coordonate +0.1f and -0.1f give the same results)
  • When i DON’T enable (GL_TEXTURE_2D) I see the line in red as desired o_O (but not the image any more, of course) (texture z coordonate +0.1f and -0.1f give the same results)

Any idea ?

[This message has been edited by acerb (edited 03-11-2003).]

/* draw quads here /
draw lines here */

Yup, that’s what i finally do

Merci beaucoup / Thanks for all

For panning those objects, any better solution than changing directly the coordonates and using perspective? (1 translate after, gluOrtho2D, gluLookAt, … ?)

for scientific vizualisation, I recommend orthographic projection which does not distort the model, but sometimes ppl prefer perspective (which is more natural).

if you want to visualize multiple slices, you need to use depth buffer otherwise the rendering order determines the visible parts.

If you want to render both the quad and the contour inside the quad, you may use polygon offset which allows to force depth test to succeed for lines.

To resume I have to enable the depth_test and to switch to ortho mode, but which one? glOrtho or gluOrtho2D?

I’ve tried but I don’t have any results… black screen

How do I switch to POLYGON as you said (sorry again, and thanks x1000 for your help)

[This message has been edited by acerb (edited 03-11-2003).]

glOrtho and gluOrtho are identical. It’s just a matter of syntax preference since the only difference is the order and definition of the parameters. If your screen is black, I guess you’re sending wrong parameters. Which arguments do you send to glOrtho/gluOrtho, and which were the ones you sent to gluPerspective/glFrustum ?

I see that you’re using depth_factor as a factor for ‘pushing the quads’ behind the lines. So I guess you want the lines to be ‘in front of’ the quads. The problem is that this depth_factor displaces the quad, which in 3D may look weird. Polygon offset allows to render multiple objects at the same place but offset the depth in order to force the z test to fail or succeed.

[This message has been edited by vincoof (edited 03-11-2003).]

I use
gluPerspective (60, (GLdouble)w/ (GLdouble)h, 0.1, 1000.0);
and tried
glOrtho(0, 768, 768, 0, 0, -20);
for the view.
The depth factor is the easiest method I found on my own to do a zoom on my 2D texture (and countour, same depth_factor) and work well… Maybe not the best method, any suggestion is good ^^

Thanks a lot again

Then if you want to zoom yourself, you may not use polygon offset. Though, for zooming I would rather recommend glScale.

I think your orthogonal projection is wrong wince you’re sendig way too big arguments.

If I were you I’d try with 7.68 instead of 768, or even smaller… try to tweak the param to get the closest match.

Also, I would rather call glOrtho(0, 768, 0, 768, -20, 0);
instead of glOrtho(0, 768, 768, 0, 0, -20);

It works well with
glOrtho(-0.5, 0.5, -0.5, 0.5, 1., -1.);

Now I’ve cleaned up my code and use glTranslate to pan and glScalef to zoom with an orthogonal projection for the view. It seems ok…

But I’d like to ask you a last thing. Someone told me that it’s better to use translate (with a depth_factor) for the zoom as I already use one for the pan function (so it’s just 1 transformation to do). Or it’s better to use glScalef and glTranslate ?

The guy that told you to use glTranslate is an idiot.
It’s not flexible, you’ve got not much control about the zoom factor and it’s not even faster. Moreover, if you ever decide to visualize your shape in 3D, the translation will mess up about everything because the lines and the textured quad will not be in the same plane.

The only thing that could be useful with translating is that it offsets the depth values, but since you don’t even look for that kind of effect it’s no use to translate anymore.

Thanks a lot for all ^^

He’s mad about your answer but it seems ok to me. I’ll continue using glPan…

I think this topic is finished