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 4 of 4

Thread: OpenGL clipping problem

  1. #1

    OpenGL clipping problem

    Hi everyone,

    I recently started exploring OpenGL on Linux (RH 7.2) and am having a clipping problem. It seems like no matter what I do, everything I put on the screen is clipped before z=1.0 and after z=-1.0 and I can't change it. Can someone give me pointers here? (I can send source code if necessary, but I'll hold off for now to save space.)

    Thanks

  2. #2
    Guest

    Re: OpenGL clipping problem

    I think it is best to post a small but complete program showing exactly what you are doing. Post it here or in the beginners forum if it is not linux specific.

  3. #3

    Re: OpenGL clipping problem

    Ok...here's some simplified source code.(It draws a grid of lines. Notice the clipping on the front and back of the surface.

    I'm not sure if this is Linux specific, but after comparing with some other platform code, I feel it might be.

    Also, I've tried things like gluOrtho and tried a bunch of other random stuff, and ju
    st can't figure out what I need to adjusting the clipping bounds.

    /************************ clippingprob.c **
    *******************************************/
    #include <GL/gl.h>
    #include <GL/glut.h>

    void display(void);
    void Line(GLfloat, GLfloat, GLfloat, GLfloat);

    int main(int argc, char** argv)
    {
    glutInit (&argc, argv) ;
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
    glutInitWindowSize (500, 500) ;
    glutInitWindowPosition (100, 100) ;
    glutCreateWindow ("OpenGL Display Window") ;

    glClearColor(0.0, 0.0, 0.0, 0.0) ;
    glMatrixMode(GL_PROJECTION);
    glutDisplayFunc (display) ;

    glutMainLoop () ;

    return 0 ;
    }

    void display(void)
    {
    int idx;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
    glLoadIdentity();
    glRotatef(80.0, 1.5f, 0.7f, 0.0f);

    //Draw a 20x20 line grid from (-1.0,-1.0,0.0) through (1.0,1.0,0.0);
    glColor3f(1.0f,1.0f,1.0f);
    for(idx = 0; idx <= 20; idx++)
    Line(1.0f, (-1.0f) + (GLfloat)idx / 10.0f,
    -1.0f, (-1.0f) + (GLfloat)idx / 10.0f);
    for(idx = 0; idx <= 20; idx++)
    Line((-1.0f) + (GLfloat)idx / 10.0f, -1.0f,
    (-1.0f) + (GLfloat)idx / 10.0f, 1.0f);

    glutSwapBuffers();
    }

    void Line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) {
    glBegin(GL_LINES);
    glVertex2f(x1,y1);
    glVertex2f(x2,y2);
    glEnd();
    }

    /********************* EOF *****************/

    compilation: gcc clippingprob.c -lGL -lGLU -lglut -lm -o clippingprob

    Thanks

  4. #4
    Guest

    Re: OpenGL clipping problem

    The red book says about gluOrtho2D:
    "For the special case of projecting a two-dimensional image onto a two-dimensional screen, use the Utility
    Library routine gluOrtho2D(). This routine is identical to the three-dimensional version, glOrtho(),
    except that all the z coordinates for objects in the scene are assumed to lie between -1.0 and 1.0. If you're
    drawing two-dimensional objects using the two-dimensional vertex commands, all the z coordinates are
    zero; thus, none of the objects are clipped because of their z values."

    If you do not have the red book can you download it from the online books section here http://gamedev.net/reference/list.asp?categoryid=31

    You can use glOrtho but probably is gluPerspective or glFrustum the functions you want to use.

Posting Permissions

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