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

Thread: 2d glOrtho - Low precision

Hybrid View

  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 fucked 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.8);
    glEnd();

    CurrentTick += m_TickSpacing;
    }

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,144
    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.

Posting Permissions

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