how can i setup a custom coordinate in opengl? let it draw geometry with my corrdinate ,for example, a point in my coordinate is (27008.123,46890.323)
a line 's coordinate (37689.323,22455.433),(36999.23,25324.5454) .
how can i draw these? please give me some example code,thank you very much !
There are some functions to do that: glOrtho, glFrustum, gluPerspective, glulookAt. With these You should be able to setup projection/coordinate system You want, and move in 3D space.
couple of links:
there is a lot of code on the net (google around these functions.)
OpenGL projection explained in detail:
What do you mean with custom coordinates?
Also, you want to draw 2D? (the coords u show are 2D)
i have much of GIS data, i want these shown in opengl, these data’s coordinate are not like (1,0,0),(0,1,0), that’s real world coordinate such as WGS84’s longitude & latitude ,how can i draw in opengl ? i want to draw a line use (123.223,31.243,0),(123.667,31.567,0) ,not like opengl’s examples that draw line only using (1,0,0),(0,1,0)
With options something like:
glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, 100000.0, 0.0, 100000.0 );
You can use something big like that as a generic value if you know that the coordinate will be no bigger than that, say, or derive the size by iterating over your data and getting the max X and Y value. If some coordinates go negative then you might need to get the minimum value for left/bottom.
I don’t recall at the moment but to keep things straight you might need to maintain your windows aspect ratio with those values too… so if your window is 640x480 which has an aspect ratio of 1.33, then you’ll want something more like (0.0,133333.3,0.0,100000.0).
Maybe something like:
double aspect = (double)windowWidth / windowHeight; double viewSize = 1e+5; glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, viewSize * aspect, 0.0, viewSize );
That last bit might not be true, I honestly forget if it’s necessary with ortho viewports. I suspect strongly that it is though.
for example ,a point with coordinate (76541.212,65322.444) ,no Z
value,in opengl ,glBegin(gl_point);glVertex3f(76541.212f,65322.444f,0.0f);glEnd();
this point ,how can i setup ,then see it ? all geometry will be drawn like this point’s coordinate.
Just like I showed above. Make sure that the size you pass to glOrtho2D is bigger than the biggest coordinate and you’ll see it. Also, I don’t think this is necessary, but I find it helpful to set the Z coordinate to -1.0.
like these point,how can i draw at Opengl ?
the max extent is letf:461000 top:3472000 right:520000 bottom:3554000
NAME x y
point1 504018 3516920
point2 502969 3517420
point3 503373 3517060
point4 503945 3516710
point5 503934 3516590
point6 504748 3517100
point7 505118 3516720
point8 503284 3516360
point9 503360 3516230
point10 504908 3515930
point11 504942 3516030
point12 505330 3515610
point13 503055 3516180
point14 504753 3515310
First step is to get a program working that can draw points at (1,0,0) and (0,1,0).
Can you do that?
If so, you’ve done 99% of the work necessary to solve your GIS problem.
You won’t need any help from the forum if you can do that.
thanks everyone, changing viewpoint & scale ,it’s ok !