Question

Based on the dynamic data, I need to draw a 2D line graph dynamically using openGL. Since, the data varies, the final drawing of the graph also needs to be adjusted such that both X-axis's and Y-axis's max and min values should be viewed. I tried several ways using glortho, could any one suggest me the formula for this,

My x-axis max value is 10,000.0f and Y-axis max value is 64,468.0f (assume x-axis n y-axis min val are around 1.0f)

glOrtho(-0.0,Winwidth,0.0,Winheight,0.0f,1.0f);

if I use above parameters I'm unable to view max and min values of the graph

glOrtho(-1.0f,maxXval,1.0,maxYval,0.0f,1.0f);

the above one works fine when max values are large,

what if the maxvalues are less then 1 for the above example, then the viewing area is being clipped because left value is 1 and similarly, bottom value is 1?

Was it helpful?

Solution

How about

glOrtho(minXvalue, maxXvalue, minYvalue, maxYvalue, -1, 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top