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: problem with 2d opengl

  1. #1

    problem with 2d opengl

    I'm attempting to small 2d game in OpenGL just for the hell of it. my code to set up the 2d view is :
    glViewport(0,0,640,480);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f,640.0f,480.0f,0.0f,-1.0f,1.0f);
    glMatrixMode(GL_MODELVIEW);
    This is supposed to make my screen coordinates the same as my screen height and width, (640x480) But if I translate to 10,10,-2 nothing appears on the screen. Can anybody give me some direction on what to do?
    Thanks,
    Joe

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2000
    Location
    B.C., Canada
    Posts
    397

    Re: problem with 2d opengl

    Do you have culling enabled? Because you are flipping the image vertically with the projection matrix, face winding is reversed. Try glCullFace(GL_FRONT) OR glFrontFace(GL_CW).

    j

  3. #3
    Guest

    Re: problem with 2d opengl

    I think your glOrtho parameters are out of order. I am doing the exact same thing as you heres my code:

    glViewport(0, 0, w, h);
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0.0, (float)w, 0.0, (float)h, 0.0f, 10.0f );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

  4. #4
    Guest

    Re: problem with 2d opengl

    Second last parameter in my glOrtho call should be -10.0f

  5. #5
    Intern Newbie
    Join Date
    May 2001
    Posts
    41

    Re: problem with 2d opengl

    Well, (10,10,-2) is out of visualization cube given by
    glOrtho(0.0f,640.0f,480.0f,0.0f,-1.0f,1.0f);
    so that coordenates are clipping.

    Change z clipping planes to the maximun amd minimun coordenates that you need to be displayed. By example:

    glOrtho(0.0f,640.0f,480.0f,0.0f,-maxZ,maxZ);

  6. #6

    Re: problem with 2d opengl

    j,
    I don't have any culling enabled
    Jackson Harper,
    You're right, I just check the parameters. Will fix it when I get home. thanks.
    Boresight,
    I wasn't exactly sure about those parameters. thanks for clearing that up for me. that helps out a lot.
    thanks for the help guys,
    Joe

Posting Permissions

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