From the source code, I know that mglCanvas::B is responsible for converting mathematic coordinates to screen coordinates.
At the beginning,
B.x = w/2, 'w' is picture's width.
B.y = h/2, 'h' is picture's height.
w 0 0
B.b = 0 h 0
0 0 sqrt(w*h)
Now let's transform the origin (0 0).
According source code in mglCanvas::PostScale, with mglCanvas object, the result is (w/2 h/2). It is easy to understand and the fact is so.
With mglCanvasGL, its constructor sets w =1 and h = 1, the transformed result should be (0.5 0.5), but the fact is that the transformed result is still (0 0) in OpenGL's coordinate system.
I have been confused for a few days, but I can not find the reason. would you please to tell me why?
BTW: Following code causes my program crashing:
gr = mgl_create_graph_gl();
...
mgl_add_legend( gr, "test-1", "r1" );
mgl_legend( gr, 3, "#", "" ); // crashing here
If I use mgl_create_graph, it's OK.
I am not sure whether it is a bug, or my code is not correct.
My compiler is vc2008 sp1, OS is winxp sp3.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This depend on how coordinates are assumed to be in OpenGL and in bitmap. In bitmap coordinates naturally measured in range [0...w][0...h], and center should be at (w/2, h/2). In OpenGL coordiantes are supposed to be in range [-1,1][-1,1] by default, and center should be at (0,0).
I'll check yours code. Which MathGL version produce the bug? Do you test it with latest one (v.2.2)?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2013-12-31
Thanks for your direction.
I traced the program agian and found the reason.
In OpenGL version, origin(0 0) is transformed to (0.5 0.5) which is stored in an array.
Before drawing, mglCanvas::pxl_transform is called, this function convers origin from (0.5 0.5) to (0 0).
As to the bug, I have tested the code with v2.2, the program is OK with mgl_create_graph_gl().
the library was created from source code with vs2008. I only used two option - enable-double, enable-opengl.
BTW: I found the line width does not work with OpenGL version (mglCanvasGL). The following code set the line width 4, but the result is 1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2014-11-20
Sorry if this thread is a little bit older,
but I would also like to know, how to fix or if there will be a fix in the future for Plot (line width) problem using GLUT/Opengl.
I am currently trying the newest MathGL v2.3.1 (vs2012).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the question:
From the source code, I know that mglCanvas::B is responsible for converting mathematic coordinates to screen coordinates.
At the beginning,
B.x = w/2, 'w' is picture's width.
B.y = h/2, 'h' is picture's height.
B.b = 0 h 0
0 0 sqrt(w*h)
Now let's transform the origin (0 0).
According source code in mglCanvas::PostScale, with mglCanvas object, the result is (w/2 h/2). It is easy to understand and the fact is so.
With mglCanvasGL, its constructor sets w =1 and h = 1, the transformed result should be (0.5 0.5), but the fact is that the transformed result is still (0 0) in OpenGL's coordinate system.
I have been confused for a few days, but I can not find the reason. would you please to tell me why?
BTW: Following code causes my program crashing:
gr = mgl_create_graph_gl();
...
mgl_add_legend( gr, "test-1", "r1" );
mgl_legend( gr, 3, "#", "" ); // crashing here
If I use mgl_create_graph, it's OK.
I am not sure whether it is a bug, or my code is not correct.
My compiler is vc2008 sp1, OS is winxp sp3.
This depend on how coordinates are assumed to be in OpenGL and in bitmap. In bitmap coordinates naturally measured in range [0...w][0...h], and center should be at (w/2, h/2). In OpenGL coordiantes are supposed to be in range [-1,1][-1,1] by default, and center should be at (0,0).
I'll check yours code. Which MathGL version produce the bug? Do you test it with latest one (v.2.2)?
Thanks for your direction.
I traced the program agian and found the reason.
In OpenGL version, origin(0 0) is transformed to (0.5 0.5) which is stored in an array.
Before drawing, mglCanvas::pxl_transform is called, this function convers origin from (0.5 0.5) to (0 0).
As to the bug, I have tested the code with v2.2, the program is OK with mgl_create_graph_gl().
the library was created from source code with vs2008. I only used two option - enable-double, enable-opengl.
BTW: I found the line width does not work with OpenGL version (mglCanvasGL). The following code set the line width 4, but the result is 1.
mgl_line(gr, 0, 0, 0, 1, 1, 0, "b4", 2 );
mgl_add_legend( gr, "test-1", "r4" );
In bitmap version (mglCanvas), it's all right.
Sorry if this thread is a little bit older,
but I would also like to know, how to fix or if there will be a fix in the future for Plot (line width) problem using GLUT/Opengl.
I am currently trying the newest MathGL v2.3.1 (vs2012).