Results 1 to 2 of 2

Thread: 2d glOrtho - Low precision

  1. #1
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    1

    Question 2d glOrtho - Low precision

    Hi guys,
    I am trying to draw an axis for a 2d-plot.
    Specifically I am trying to draw the ticks on that axis.
    Unfortunately I ran into some precision problems. As soon as the range between min and max exceeds single precision (32 bit float)
    the ticks are ****ed up or all drawn at the same position.

    Example: m_NiceMin = 1.1111111 and m_NiceMax = 1.1111112
    In double precision there is no problem, in single precision it is all 1.1111112 and therefore drawn in the same place.

    Here is my code. Hope you can help me out.

    // Set drawing area
    _u32 AxisWidth = m_ControlRect.Width() - 2*BorderSize - YAxisWidth;
    glViewport(BorderSize + YAxisWidth, // X0
    BorderSize, // Y0
    AxisWidth, // Width
    m_BaseSize + AxisTitleSize // Height
    );

    glLoadIdentity();
    glOrtho(m_NiceMin, m_NiceMax, 0, 1, -1, 1);


    // Draw the ticks on the right side of the axis
    double CurrentTick = m_NiceMin + m_TickSpacing;
    for (_u32 i = 1; i < Ticks; i++)
    {
    // Draw tick line
    glBegin(GL_LINE_STRIP);
    glVertex2d(CurrentTick, 1);
    glVertex2d(CurrentTick, 0.;
    glEnd();

    CurrentTick += m_TickSpacing;
    }

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    You must change your drawing logic. CurrentTick is internaly converted to single precision float. "d" in the funcion call does not mean OpenGL will use doubles. In any case, there is no need for double precision for what you want to do.

Similar Threads

  1. glOrtho
    By minidrive in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-27-2013, 09:44 PM
  2. glortho
    By giugio in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-13-2012, 12:38 AM
  3. glOrtho use?
    By eanton in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-11-2010, 02:39 AM
  4. glortho ?!
    By gunsboy in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-22-2002, 04:39 AM
  5. single precision floats vs. double precision
    By BigD in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-02-2001, 12:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean