PDA

View Full Version : glVertex*f lines not working over a 2D texture



acerb
03-11-2003, 03:58 AM
Hi,

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... http://www.opengl.org/discussion_boards/ubb/frown.gif

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 (512*512)
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
glVertex2f(C1[i].x,C1[i].yF);
glEnd ();
glPopMatrix ( );
}


void display ( void ) {
//tried with the depth bit as well
//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear (GL_COLOR_BUFFER_BIT);
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
Thanks.

acerb

vincoof
03-11-2003, 04:01 AM
What contour do you expect to see ? The contour of the quad (4 lines) or the contour of the image inside the texture ?

acerb
03-11-2003, 04:15 AM
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... =/

vincoof
03-11-2003, 04:19 AM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif

vincoof
03-11-2003, 04:22 AM
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).]

acerb
03-11-2003, 04:24 AM
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...

vincoof
03-11-2003, 04:25 AM
Also, have you checked the coordinates of your contour ? Do they range between [tempX,tempX+1]x[tempY,tempY+1] ? Is the quad visible ?

acerb
03-11-2003, 04:26 AM
How do I draw lines wihtout textured? Isn't it already the case (glvertex* is in line_loop mode, not in quads)...

acerb
03-11-2003, 04:34 AM
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 ?

acerb
03-11-2003, 04:46 AM
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).]

vincoof
03-11-2003, 05:44 AM
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
/* draw quads here */
glEnd();
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINE_LOOP);
/* draw lines here */
glEnd();

acerb
03-11-2003, 05:54 AM
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, ... ?)

vincoof
03-11-2003, 06:27 AM
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.

acerb
03-11-2003, 06:52 AM
Allright!!
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).]

vincoof
03-11-2003, 07:34 AM
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).]

acerb
03-11-2003, 11:15 PM
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

vincoof
03-12-2003, 02:01 AM
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);

acerb
03-12-2003, 05:36 AM
It works well with
glOrtho(-0.5, 0.5, -0.5, 0.5, 1., -1.);
Thanks

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 ?

vincoof
03-12-2003, 10:29 AM
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.

acerb
03-13-2003, 04:22 AM
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

vincoof
03-13-2003, 10:58 AM
Mind me, I do not really think that "he is truly an only an idiot". It's just the glTranslate solution that is very bad for what I know about your problem.
But probably he has his own reasons that are useful for other points that you did not detailed in this topic.

Sorry for flaming. I know it's forbidden and I deserve to be banned for that !

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

acerb
03-14-2003, 12:35 AM
Hey, there was no problem at all about this, I was just a lil' acerbic with him ^^ He's glad he learns something and he doesn't know a lot more than you about my project anyway!

In resume you were not flaming, I was... And your answer was the right one and he agrees with your point of vue.

Thanks for all (especially for writing all that in english altough we both speak french =P)

acerb (@softhome.net)

Add :
Do you know why I couldn't get the transparence out of any texture or quad over my texture ?

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