Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: GL_POINTS to mesh please

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    GL_POINTS to mesh please

    Hi,
    Think i am missing something very simple.

    Have vertex points that render correctly a human torso (with arms and hands) using glDrawArrays' GL_POINTS. When trying the "other" modes, such as GL_POLYGON or GL_TRIANGLES, there are lines, or surfaces coming from the hands to the stomach.

    Am I missing a step that tells OpenGL to render it as a mesh? Perhaps, have to render each part separately (i.e. fingers, hands, arms, etc?)

    Thank you.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Please supply a little code. Does each set of 3 vertices make a valid triangle when you change to GL_TRIANGLES and each pair make a valid line for GL_LINES

  3. #3
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3
    Appreciate the quick reply.

    Don't believe they make a valid triangle nor valid line. But for the code:

    Code cpp:
    - (void)drawRect:(NSRect)dirtyRect
    {
        //NSLog(@"Redraw");
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_AUTO_NORMAL);
        glEnable(GL_NORMALIZE);
     
        glShadeModel(GL_SMOOTH);
     
        glEnable(GL_POLYGON_SMOOTH);
        glPolygonMode(GL_FRONT, GL_POINTS);
     
        // clear our drawable
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
     
        Vector3 color = {1.0f,0.85f,0.35f};
        [self drawAnObject:hair color:color imageName:nil];
        color.x = 1.0f; color.y = 0.0f; color.z = 0.0f;
        [self drawAnObject:head color:color imageName:@"face.png"];
    //    color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
    //    [self drawAnObject:eye color:color imageName:nil];
        color.x = 0.0f; color.y = 1.0f; color.z = 0.0f;
        [self drawAnObject:upper_body color:color imageName:@"upper.png"];
        color.x = 0.0f; color.y = 0.0f; color.z = 1.0f;
        [self drawAnObject:lower_body color:color imageName:@"lower.png"];
    //    color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
    //    [self drawAnObject:skirt color:color imageName:nil];
     
        if ([self inLiveResize] && !fAnimate)
            glFlush ();
        else
            [[self openGLContext] flushBuffer];
        //glReportError ();
    }
     
    // ---------------------------------
     
    - (void) drawAnObject:(PolyMesh *)polyMesh color:(Vector3)color imageName:(NSString *)imageName
    {
        if (imageName != nil) {
            // allocate a texture name
            glGenTextures( 1, &textureid );
     
            // blending
            glEnable( GL_TEXTURE_2D );
     
            // load the texture
            NSString *filePath = [[NSBundle mainBundle] pathForResource:[imageName stringByDeletingPathExtension] ofType:[imageName pathExtension]];
            textureid = SOIL_load_OGL_texture([filePath UTF8String], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
            if (0 == textureid) {
                NSLog(@"Failed to load texture %@!", imageName);
            } else {
                NSLog(@"Loaded texture %@!", imageName);
     
                glBindTexture(GL_TEXTURE_2D, textureid);
                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
                //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
                glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
                glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
                glEnableClientState( GL_TEXTURE_COORD_ARRAY );
                glTexCoordPointer(2, GL_FLOAT, 0, polyMesh.single_texCoords);
            }
        } else {
            NSLog(@"Texture passed as nil.");
        }
     
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);
     
        glNormalPointer(GL_FLOAT, 0, polyMesh.single_normals);
        glVertexPointer(3, GL_FLOAT, 0, polyMesh.single_vertices);
        glColor3f(color.x,color.y,color.z);
        glDrawArrays(GL_LINES, 0, polyMesh.numVertices);
     
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_NORMAL_ARRAY);
     
        if (imageName != nil) {
            if (0 != textureid) {
                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                glDeleteTextures(1, &textureid);
            }
        }
    }

    Thank you.
    Last edited by Dark Photon; 11-04-2012 at 07:22 AM.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,190
    Please use [code]...[/code] or [highlight=cpp]...[/highlight] blocks for code. Inserted them for you.

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,190
    You said it renders fine as GL_POINTS, but that's not what you want as you're trying other primitive types. And I don't think you really stated what you want to see (you need to tell us that).

    Is this a joint tree? Do you want to render lines between each parent and child joint pair? If so, then GL_LINES will do what you want. But you of course need to know which point pairs represent parent and child pairs. glDrawArrays will work, but even simpler is glDrawElements.

  6. #6
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3
    Hi, reposting.

    Not 100% sure what order the vertices are in. Thought as long as the shape was (hopefully) convex, that OpenGL would magically display the surfaces lol.


    - (void)drawRectNSRect)dirtyRect
    {
    //NSLog(@"Redraw");
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEP TH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_AUTO_NORMAL);
    glEnable(GL_NORMALIZE);

    glShadeModel(GL_SMOOTH);

    glEnable(GL_POLYGON_SMOOTH);
    glPolygonMode(GL_FRONT, GL_POINTS);

    // clear our drawable
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);

    Vector3 color = {1.0f,0.85f,0.35f};
    [self drawAnObject:hair color:color imageName:nil];
    color.x = 1.0f; color.y = 0.0f; color.z = 0.0f;
    [self drawAnObject:head color:color imageName:@"face.png"];
    // color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
    // [self drawAnObject:eye color:color imageName:nil];
    color.x = 0.0f; color.y = 1.0f; color.z = 0.0f;
    [self drawAnObject:upper_body color:color imageName:@"upper.png"];
    color.x = 0.0f; color.y = 0.0f; color.z = 1.0f;
    [self drawAnObject:lower_body color:color imageName:@"lower.png"];
    // color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
    // [self drawAnObject:skirt color:color imageName:nil];

    if ([self inLiveResize] && !fAnimate)
    glFlush ();
    else
    [[self openGLContext] flushBuffer];
    //glReportError ();
    }

    // ---------------------------------

    - (void) drawAnObjectPolyMesh *)polyMesh colorVector3)color imageNameNSString *)imageName
    {
    if (imageName != nil) {
    // allocate a texture name
    glGenTextures( 1, &textureid );

    // blending
    glEnable( GL_TEXTURE_2D );

    // load the texture
    NSString *filePath = [[NSBundle mainBundle] pathForResource:[imageName stringByDeletingPathExtension] ofType:[imageName pathExtension]];
    textureid = SOIL_load_OGL_texture([filePath UTF8String], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
    if (0 == textureid) {
    NSLog(@"Failed to load texture %@!", imageName);
    } else {
    NSLog(@"Loaded texture %@!", imageName);

    glBindTexture(GL_TEXTURE_2D, textureid);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glTexCoordPointer(2, GL_FLOAT, 0, polyMesh.single_texCoords);
    }
    } else {
    NSLog(@"Texture passed as nil.");
    }

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glNormalPointer(GL_FLOAT, 0, polyMesh.single_normals);
    glVertexPointer(3, GL_FLOAT, 0, polyMesh.single_vertices);
    glColor3f(color.x,color.y,color.z);
    glDrawArrays(GL_LINES, 0, polyMesh.numVertices);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

    if (imageName != nil) {
    if (0 != textureid) {
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDeleteTextures(1, &textureid);
    }
    }
    }

Posting Permissions

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