View Full Version : 2d glOrtho - Low precision

10-04-2013, 02:14 AM
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

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
glVertex2d(CurrentTick, 1);
glVertex2d(CurrentTick, 0.8);

CurrentTick += m_TickSpacing;

10-04-2013, 07:38 AM
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.