PDA

View Full Version : Simple graphical project, satellite tracking / visualization



thor36
04-18-2014, 10:19 AM
Hello,

I would like to create a simple satellite tracking / visualization software with OpenGL, that would result in something like this :

http://www.agi.com/images/media-center/multimedia/current-events/us-spy-satellite/DebrisGroundTrack.jpg
( I did not produce and don't own the image, I found it by image searching )
It is basically a map of Earth on which points are projected, that represent satellite's position above that location on Earth. Of course these points move in time and create a line. I have the calculations part covered, I believe, but I don't know about graphical implementation.

I have C++ experience and no OpenGL experience. I have a video card that supports OpenGL 3.2 , but someone recommended me to use legacy OpenGL for such a simple project. I am little doubtful, because I would like to learn core profile, that will be of use for me in future too. But legacy coding is supposed to be much easier. Can I have your opinions on it ? And maybe some online resources / books / tips that will help me get the basics I need to complete my project ?

Thank you, it is much appreciated
thor36

Aleksandar
04-19-2014, 02:32 AM
Your project is extremely simple. If you want to learn modern OpenGL, then and only then you should use OpenGL 3+. But the development would last very long. Using legacy (fixed function) OpenGL would be faster and can be executed virtually on everything. But, if you want to achieve results in an hour, use some 2D API. You just need drawing a bitmap and few simple primitives like lines and circles.

nbdspcl
04-19-2014, 03:15 AM
> but someone recommended me to use legacy OpenGL for such a simple project

Maybe someone recommended just what he/she just got used to. New OpenGL API is even simpler than the legacy immediate mode: you fill a buffer with vertices to draw, attach this buffer to the context and call the draw command.

thor36
04-19-2014, 03:48 AM
You see, that is why I am confused. You both gave me great answers ( thanks for that ! ), but different ones. And it is same when I do research on 'old' vs 'new' OpenGL on my own - I can't figure out the best option, and they both seem to be about equal with pros and cons. And I would like to use OpenGL because of its versatility and possible projects in the future. The part with " Using legacy (fixed function) OpenGL would be faster and can be executed virtually on everything " seems to be giving an edge.

Maybe you can give me additional comments if I let you know that next stage of my project ( after completing this simple one ) would be a Solar system simulation, resulting in something like this :

https://sp2.yimg.com/ib/th?id=HN.608055098785925206&pid=15.1
( again I did not produce and don't own the image, I found it by image searching )

Aleksandar
04-19-2014, 05:40 AM
This is also fairly easy. Fixed functionality is easier (up to certain extent) but shader based approach is more flexible. If you are ready to learn, start with GL 3+, but be prepare to spend a long long time before achieving some result. But the next step to something more complicated would be much easier. Drawing a triangle or a pretty complicated mesh is almost the same in moder OpenGL. On the other hand, you can achieve same simple results much faster with legacy OpenGL, but maybe you'll come to a point where it cannot be used any more (for example, per pixel lighting). Maybe it is best for you to find some examples in both legacy and moder OpenGL and compare the code. You'll need a lot more accompanying libraries (or implement by yourself) if you follow the moder path. Everything you showed in the downloaded pictures can be quite easily implemented using legacy OpenGL.

Aleksandar
04-19-2014, 05:48 AM
Maybe someone recommended just what he/she just got used to. New OpenGL API is even simpler than the legacy immediate mode: you fill a buffer with vertices to draw, attach this buffer to the context and call the draw command.
And load new functions not exposed by windowing API, and make shaders for drawing, and make some shaders loading code, and make buffers for even the smallest primitives (or make them procedurally), and make and select VAO (even if you are not using it), and implement all maths for vector/matrix manipulation, and implement transformations, and ... Sounds simple, isn't it? ;)

But, at the point when one has all this and achieves some skills, there will be no limitations. Shader-based approach is extremely powerful.

thor36
04-19-2014, 06:00 AM
Alexandar thank you for your comments. I think this settles it, for now I will go with legacy OpenGL, and leave the modern one when I will complete these projects and have the luxury of more time. Now that you know what kind of results I would like to achieve with legacy OpenGL, can you ( or anyone else too ) point me to some resources that you recommend ( books & tutorials ) ? I have already been looking for them and found some, but as a beginner I may not do a good selection, and I probably missed some good ones too. I will be using C++ and CodeBlocks. Also, GLUT / FreeGLUT is used in most tutorials, but people recommend GLFW. Thank you for your help.

Aleksandar
04-21-2014, 03:18 AM
What books and tutorials have you found?
For the beginning I would recommend OpenGL Programming Guide (pre-8th edition). There is also online (http://www.glprogramming.com/red/) version of some of the earliest editions. You need to read just first four chapters to get basic skills and a half of ninth chapter for texturing (you need it to draw a map). For the second phase (the solar system), you may need also fifth chapter (lighting).

thor36
04-21-2014, 05:38 AM
I have found these :
- http://www.swiftless.com/opengltuts.html
- http://lazyfoo.net/tutorials/OpenGL/index.php
- SuperBible OpenGL book on amazon

So far I have been checking swiftless tutorial. It seems ok, but texturing only shows how to load RAW images, and my map will be either JPEG / BMP / PNG / TIFF. And I will probably want to move from FreeGLUT to GLFW at some point. I would like my program to be able to run on Linux and Windows, with as little changes as possible before compilation.

Also I would like opinion from you about these two books I found, whether they would apply well for my project and which version would be more suitable :
- First one (http://www.amazon.co.uk/OpenGL-Programming-Guide-Official-Learning/dp/0321335732/ref=sr_1_3?ie=UTF8&qid=1398090232&sr=8-3&keywords=open+gl+programming+guide+2)
- Second one (http://www.amazon.co.uk/OpenGL-Programming-Guide-Official-Learning/dp/0321481003/ref=sr_1_1?ie=UTF8&qid=1398089760&sr=8-1&keywords=OpenGL+Programming+Guide%3A+The+Official+ Guide+to+Learning+OpenGL%2C+Version+2)

fiodis
04-21-2014, 07:12 AM
As far as image loading goes, you could read up on each file format and make your own loader, or you could use a image loading library. A good lightweight, easy to use, cross platform one is SOIL (http://www.lonesock.net/soil.html), which can load BMP, JPG, PNG, and others more besides (though not TIFF). Another popular one is DevIL (http://openil.sourceforge.net/features.php), which can load an even larger range of formats including TIFF, though it's slightly larger than SOIL.

thor36
04-21-2014, 07:29 AM
Thank you fiodis. I have already tried with SOIL ( I chose it over DevIL because I don't need such big library with so many supported formats ). But I get a flawed texture rendering. I tried it on a swiftless tutorial example with creating a sphere and binding bitmap Earth texture on it. With SOIL I get only upper hemisphere textured , and on one "meridian" an ugly texture "stitch" appears.

fiodis
04-21-2014, 07:57 AM
I'm not sure which tutorial you're using, but if you're using this (http://www.swiftless.com/tutorials/opengl/sphere.html) one then it looks like the bottom half has negative texture coordinates. Normally texture coordinates range from 0 to 1. To go beyond that you need to specifically enable texture wrapping. See glTexParameter (https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml); you'll want to enable GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T. Swiftless has an example in their code following that tutorial.

thor36
04-21-2014, 08:41 AM
Fiodis - yes that was the tutorial I was mentioning. And what you said was exactly what was missing in my code, thank you. If you are familiar with OpenGL literature, I would kindly like to ask you to give me your opinion on my post #9 (https://www.opengl.org/discussion_boards/showthread.php/184035-Simple-graphical-project-satellite-tracking-visualization?p=1259026&viewfull=1#post1259026), while I am eagerly awaiting Alexandar's opinion. If you feel like it that is, so no need to bother with it if you don't =)

Carmine
04-21-2014, 01:50 PM
I would like to create a simple satellite tracking / visualization software with OpenGL, ... someone recommended me to use legacy OpenGL .... I use legacy GL to do my satellite sims (which are animated). A screen grab is attached. Use gluSphere with textures activated to eliminate that ugly seam you're running into. I load bmps and tga files using code I grabbed off the web. I also use Devil to load images. Legacy GL is capable enough to generate the graphics you are interested in. I haven't tried to mess around with Modern GL. It looks like the learning curve is steep. If you were going to be a full time graphics application developer, it would be the way to go. If you're primary interest is in some other area (such as engineering), and you are doing graphics on the side, I'd recommend Legacy GL. The NeHe Graphics Legacy tutorials are good. There are lots of them, but you only need to do the first 6 or so for your application.

1268

thor36
04-21-2014, 01:59 PM
Carmine, your project looks awesome. Close ( well, much better ) to what I expect to achieve some time. Is there a website with more information about your project available ? Also thank you for the extra tips in your post, much appreciated.

Carmine
04-21-2014, 02:18 PM
Carmine, your project looks awesome. Is there a website with more information about your project available? Thanks. My work is not documented outside my company because it is being developed in a classified environment. But that should not discourage you. The 'look' of my graphics is result of practice, not graphics sophistication. It is done with basic, Legacy, GL - all of which is covered in the first 6 NeHe Tutorials. Orbit visualization software can be purchased from companies such as AGI (www.agi.com), which is one of the more sophisticated, thus expensive packages. A search of the web would probably yield less expensive packages.

If you have no budget and/or want to do it yourself, it is fairly straightforward. Everything in my image is lines, polygons, and textures. The primary light source is the sun, with a secondary source to fill in darker areas. All of the user interface stuff is done with FLTK, which is free software.

Good luck.

Aleksandar
04-22-2014, 07:38 AM
I have found these :
- http://www.swiftless.com/opengltuts.html
- http://lazyfoo.net/tutorials/OpenGL/index.php
- SuperBible OpenGL book on amazon

So far I have been checking swiftless tutorial. It seems ok, but texturing only shows how to load RAW images, and my map will be either JPEG / BMP / PNG / TIFF. And I will probably want to move from FreeGLUT to GLFW at some point. I would like my program to be able to run on Linux and Windows, with as little changes as possible before compilation.

Also I would like opinion from you about these two books I found, whether they would apply well for my project and which version would be more suitable :
- First one (http://www.amazon.co.uk/OpenGL-Programming-Guide-Official-Learning/dp/0321335732/ref=sr_1_3?ie=UTF8&qid=1398090232&sr=8-3&keywords=open+gl+programming+guide+2)
- Second one (http://www.amazon.co.uk/OpenGL-Programming-Guide-Official-Learning/dp/0321481003/ref=sr_1_1?ie=UTF8&qid=1398089760&sr=8-1&keywords=OpenGL+Programming+Guide%3A+The+Official+ Guide+to+Learning+OpenGL%2C+Version+2)
Use tutorials just to get quick start and make the first application running, but then spend some time in getting basic knowledge from the books.
OpenGL Superbible is quite OK. It is more "tutorial" oriented, while OpenGL Programming Guide is more "reference" oriented. It would be probably good choice to start with any of these. When I started with OpenGL (about 17 years ago), the Red Book (in electronic form on SGI workstation) was everything I could get about OpenGL. Later I got several printed versions. They still collect dust on the self. ;) Maybe that's why I usually recommend the Red Book. Sentimentality or something like that... :)
Unfortunately, it seems that the latest versions of both books are not as good as they used to be, or my expectations grew very high.


Carmine, your project looks awesome. Close ( well, much better ) to what I expect to achieve some time. Is there a website with more information about your project available ? Also thank you for the extra tips in your post, much appreciated.
Your project is quite simple. You should be able to do it without any of the shelf solution.
By the way, if you are trying to visualize real Earth, you should make an ellipsoid instead of sphere. The difference is small, but it would be more scientific like...

Considering loading pictures, I recommend stb_image.c (http://nothings.org/stb_image.c). The whole "library" in a single file. You couldn't get better portability. :)
BUT, before go any further, consider using images in DXT1 format. Those format you mentioned is not good for 3D applications.
You'll get significant speedup and reduction of memory space if you use some of the texture compression formats (like DXT1/S3TC).

thor36
04-22-2014, 09:43 AM
Alexandar, I think I found the Red Book most suitable for me to start with as well. And I can see it has a very long tradition, close to my lifetime =) Do you ( or anyone ) have any idea where to get Red Book 5th and 6th edition code for download ?

Difference between equatorial and polar radius of Earth is about 20 km, it would take an XXL screen with super resolution to notice the difference =) I understand your point though, but my project really isn't so much about details like that. Speaking of that, what algorithm do you recommend me to use to create a sphere that I can texture ( "create" Earth ), so that it will be efficient and decent looking ?

I will try stb_image.c "library", thank you. But how do I go about using DXT1 / S3TC format ? How do I convert images from common formats to that one ? And what OpenGL functions use it for texturing ?

Aleksandar
04-22-2014, 01:11 PM
Do you ( or anyone ) have any idea where to get Red Book 5th and 6th edition code for download ?
There is some sample code (http://www.opengl.org/archives/resources/code/samples/redbook.zip) from the first edition, but I don't think you need it. As I said, build some sample application (from tutorials) and then try to add/change functions according to examples from the books or other tutorials.


Difference between equatorial and polar radius of Earth is about 20 km, it would take an XXL screen with super resolution to notice the difference =) I understand your point though, but my project really isn't so much about details like that. Speaking of that, what algorithm do you recommend me to use to create a sphere that I can texture ( "create" Earth ), so that it will be efficient and decent looking ?
I know very well the shape of the Earth. :)
I've spent years in implementing my algorithm for procedural completely shader based high accurate model of the WGS84 ellipsoid. Looking at the shape of the Earth solely one cannot distinguish it from the perfect sphere. But, since you want to visualize satellite paths, depending on the accuracy you need to achieve, an error sometimes is not negligible. Be aware of geodetic and geocentric latitude difference. I have no idea what formulae you are using, but they probably use latitude.

If you want to create a sphere, it is best to use two nested loops (through latitudes and longitudes), translate polar to Cartesian coordinates and use triangle strips to draw strips around the globe (each strip from Theta to Theta+dTheta in latitude and from 0 to 360 degrees in longitude). Steps should be chosen according to your needs. This is quite acceptable up to about several km above the surface If you want to implement ellipsoid, the equations are different. (By the way, my implementation is far more complicated and I wouldn't start that topic right now. And it requires shaders heavily.)


But how do I go about using DXT1 / S3TC format ? How do I convert images from common formats to that one ? And what OpenGL functions use it for texturing ?
OpenGL can compress textures automatically if internal format is set to GL_COMPRESSED_RGB_S3TC_DXT1_EXT (for DXT1/S3TC). Please read chapter 9 from the Red Book for details. Also, there are a lot of tools for offline compression.

thor36
04-22-2014, 03:25 PM
Great to know that I am receiving help from an expert in the field :) What you are telling about your work sounds very interesting. Do you mind if I ask for what purpose have you designed such an accurate model of Earth ?

Yes, the geodetic and geocentric latitude variance is another story and I will be careful about it. Whereas the exact shape of the Earth is not of essence for the orbit visualization. About the algorithm that you have just described me for creating a sphere - is it documented anywhere in terms of pseudo code or perhaps even better implemented in OpenGL already ? I can say honestly that I would like to save some sweat, time, nerves and errors with drawing a sphere, since the central point of my project are orbits and physical calculations of spacecraft motion - not to mention that I am beginner in OpenGL and that takes a lot of extra effort itself :)

Carmine
04-22-2014, 04:16 PM
... I would like to save some sweat, time, nerves and errors with drawing a sphere, since the central point of my project are orbits and physical calculations of spacecraft motion ... Google gluSphere. It generates all of the vertices and polygons making up a sphere. You have control over the number of lat-lon divisions it generates. Also, if you request, it generates texture coordinates allowing you to wrap a world map image around the sphere without any ugly seams. This is what I use in my sims.

You are smart in the way you're setting your priorities. You are developing a very small application. No need to spend a lot of time worrying about ultra-efficient OpenGL. Doing the graphics simply will allow you to concentrate on the engineering features of your sim.

Aleksandar
04-23-2014, 01:25 AM
Do you mind if I ask for what purpose have you designed such an accurate model of Earth ?
I'm a long time in 3D terrain rendering for GIS, and I wanted to develop algorithm to precisely render the whole planet using clipmaps (with cm precision or higher).
Something like Google Earth, but better. ;)


About the algorithm that you have just described me for creating a sphere - is it documented anywhere in terms of pseudo code or perhaps even better implemented in OpenGL already ? I can say honestly that I would like to save some sweat, time, nerves and errors with drawing a sphere, since the central point of my project are orbits and physical calculations of spacecraft motion - not to mention that I am beginner in OpenGL and that takes a lot of extra effort itself :)
Being in education for a long time, I prefer not to give students a complete solution. Rather I give them a clue and force them to find solution by themselves.
What I mention is a quite simple math. It needs 5 minutes to be accomplished. But, if you wish a "complete" solution this is the code:


for(double Theta = -90.0; Theta < 90.0; Theta+= dTheta)
{
glBegin(GL_TRIANGLE_STRIP);
for(double Phi = -180.0; Phi <= 180.0; Phi+= dPhi)
{
double x = r*cos(Theta*toRad)*sin(Phi*toRad);
double y = r*sin(Theta*toRad);
double z = r*cos(Theta*toRad)*cos(Phi*toRad);
glVertex3d(x,y,z);
x = r*cos((Theta+dTheta)*toRad)*sin(Phi*toRad);
y = r*sin((Theta+dTheta)*toRad);
z = r*cos((Theta+dTheta)*toRad)*cos(Phi*toRad);
glVertex3d(x,y,z);
}
glEnd();
}

This is totally unoptimized version, but is servers the purpose.The result is shown in the following picture. 1272
Next step is to define texture coordinates and normals. Then put it into a display list, vertex array or VBO.

thor36
04-23-2014, 04:08 AM
Thank you both, Carmine and Alexandar. I think I am equipped with the basic information I need for now to try tackle the project. Any tips are always welcome of course :)