Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: glVertex*f lines not working over a 2D texture

  1. #1
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    glVertex*f lines not working over a 2D texture

    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...

    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
    "Be prepared for the worst but expect the best"

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    768

    Re: glVertex*f lines not working over a 2D texture

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

  3. #3
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    Re: glVertex*f lines not working over a 2D 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... =/
    "Be prepared for the worst but expect the best"

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    768

    Re: glVertex*f lines not working over a 2D texture

    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

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    768

    Re: glVertex*f lines not working over a 2D texture

    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).]

  6. #6
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    Re: glVertex*f lines not working over a 2D texture

    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...
    "Be prepared for the worst but expect the best"

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    May 2001
    Location
    France
    Posts
    768

    Re: glVertex*f lines not working over a 2D texture

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

  8. #8
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    Re: glVertex*f lines not working over a 2D texture

    How do I draw lines wihtout textured? Isn't it already the case (glvertex* is in line_loop mode, not in quads)...
    "Be prepared for the worst but expect the best"

  9. #9
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    Re: glVertex*f lines not working over a 2D texture

    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 ?
    "Be prepared for the worst but expect the best"

  10. #10
    Intern Newbie
    Join Date
    Mar 2003
    Location
    Brussels
    Posts
    40

    Re: glVertex*f lines not working over a 2D texture

    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).]
    "Be prepared for the worst but expect the best"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •