Andy Spencer [Mon, 13 Feb 2012 23:12:20 +0000 (23:12 +0000)]
Fix memory leaks in tile loading
- Splitting a tile could accidentally overwrite a already split tile if
one (but not all) of the children were garbage collected.
- Garbage collection never actually happened.. because tile always had
empty children. To fix this a `load' flag was added so that the
children could be garbage collected as well without having to check
the data flag which may always be null.
tile->load: set when texture loading has started
tile->data: set when texture loading has finished
Andy Spencer [Sun, 12 Feb 2012 07:22:08 +0000 (07:22 +0000)]
Cast function pointers for gluTessCallback
The glu type does not work on Mac OSX, and an un-casted version does not
work in Debian.. Hopefully casting it to GCallback (void-void function)
will work both places..
Andy Spencer [Sat, 11 Feb 2012 17:32:27 +0000 (17:32 +0000)]
Delay load the textures for label markers
This makes the normal constructor thread-safe so they don't need to be
created from a callback, the same should eventually be done for the icon
markers.
Andy Spencer [Sat, 11 Feb 2012 08:14:29 +0000 (08:14 +0000)]
Load tiles at a lower resolution
The updated FOV code causes tiles to get loaded sooner than they used to
bee. While this may be "correct" it creates hard-to-read tiles because
they're so small. It also increases memory usage..
Andy Spencer [Sat, 11 Feb 2012 07:03:17 +0000 (07:03 +0000)]
Check for split on all child tiles
When tiles split, all the children will be valid so only [0][0] needs to
be checked. However, a child tile may be garbage collected in which case
there may be a NULL child tile.
Andy Spencer [Thu, 9 Feb 2012 09:20:58 +0000 (09:20 +0000)]
Add ortho flag to GritsMarker
Setting ortho to true causes the marker to be drawn orthographic and
flat against the screen. This is the default and behavior and is markers
have been drawn in the past.
Clearing the flag causes he marker to be drawn using the viewers
perspective projection but scaled to a fixed size.
Andy Spencer [Mon, 6 Feb 2012 06:32:35 +0000 (06:32 +0000)]
Add grits_viewer_unproject function
This does the opposite of the grits_viewer_project function and can be
used to get the lat-lon-elev point corresponding to a point on the
screen, such as the pointer location. This currently has an undefined
output if the screen coordinates do not map to the location of an object
in the viewer.
This should not be used to determine if an objects has been selected or
clicked on. OpenGL picking should be used for that by connecting to one
of the GritsObject mouse event signals.
Andy Spencer [Mon, 6 Feb 2012 05:41:44 +0000 (05:41 +0000)]
Rewrite expose to preserve the depth buffer
Sorted objects are now drawn with depth testing enabled. Unsorted
objects are drawn without depth testing. This mostly affects
GRITS_LEVEL_WORD+n objects.
Objects at other levels such as BACKGROUND, OVERLAY, and HUD should
generally disable sorting so that they are always drawn to the screen.
For those levels, the depth-buffer is set to read-only. This preserves
the depth buffer so that it can be used later on to get the world-level
depth at a given screen location.
Andy Spencer [Mon, 30 Jan 2012 07:50:27 +0000 (07:50 +0000)]
Improve rendering of non lat-lon tiles
There have been a long standing bugs related to this..
Up until now the solution was to only use tiles that split along
lat-long lines and to also split the geometry (in roam) along the same
lines.
Hopefully this allows tiles to be rendered properly.
See examples/tex.c for details of how this rendering works.
Andy Spencer [Mon, 30 Jan 2012 07:06:08 +0000 (07:06 +0000)]
Use multi-texturing for alpha masking in tex.c
Multi-texturing uses two textures for each fragment. The example uses
GL_TEXTURE0 as the regular texture color and a second texture as the
alpha mask. Since there are two textures they can have separate
filtering an wrapping parameters.
The color texture uses GL_MODULATE which combines it with the existing
color. The alpha mask uses GL_REPLACE which causes it to replace the
linearly filtered alpha mask from the color texture with a hard-edged
alpha mask that is clamped to transparent at the border.
This is similar to how drawing is done in NASA World Wind
Andy Spencer [Mon, 30 Jan 2012 06:39:15 +0000 (06:39 +0000)]
Use glBlendFuncSeparate for alpha masking in tex.c
The draw happens in two steps:
1. Copy the alpha mask to the framebuffer without changing the color
channels: glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO)
This uses GL_LINEAR filtering and GL_CLAMP_TO_BORDER to create a
alpha mask with hard edges as opposed to blurred edges.
2. Copy the texture color to the framebuffer using the alpha mask
stored in the frame buffer as the mask:
glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ZERO, GL_ZERO);
We can turn on GL_LINEAR filtering and GL_CLAMP here because the
alpha mask is taken from the framebuffer instead of the filtered
alpha component of the texture.
This creates a nice looking image without having to do any fancy setup.
The previous version also has issues if the texture is not split in the
middle of the polygon.
Unfortunately glBlendFuncSeparate depends on OpenGL 2.0 and requires
twice as many draws.
Andy Spencer [Mon, 16 Jan 2012 03:13:00 +0000 (03:13 +0000)]
Add Tile Map Service downloading
This uses map tiles directly from openstreetmap.org. The problem with
this is that those tiles are rendered using a Mercator projections which
is non-linear with respect to latitude. Two things must be done to
properly correct for this:
1. Split tiles at the correct location. With the Mercator projection,
the midpoint of a tile is the midpoint of the longitude but not the
midpoint of the latitude.
Correcting this very important because it prevent tiles from being
drawn in entirely the wrong place.
2. Morph each tile to lat-lon projection when it is drawn. This could
possibly be done with a OpenGL fragment shader.
This noticeable when zoomed out so it's not too bad to just ignore
the issue.. The web based map servers have similar issues with land
area at high-up zoom levels.
Eventually we'll want to fetch the XML and render the maps locally..
Andy Spencer [Sun, 8 Jan 2012 23:06:16 +0000 (23:06 +0000)]
Fix clipping plane issues
The clipping plane is flat, so the distance between the camera and the
clipping plane varies based on where screen location. I.e. it is closest
in the center and farther at the corners. Add a offset to elev to
account of this. It would be better to use a sin or to calculate
distances directly, but this is easy and appears to work.
Andy Spencer [Tue, 3 Jan 2012 07:32:34 +0000 (07:32 +0000)]
Add GritsLine
GritsLine is similar to GritsPoly, but does not draw a filled polygon.
As such it does not need to do any tessellation.
Currently it draws the points directly instead of using a display list.
This should make it easier to updated the line at runtime without
needing to create a new object.
Andy Spencer [Mon, 12 Dec 2011 05:37:20 +0000 (05:37 +0000)]
Move OpenGL includes to a common place
Apple seems to think the should put GL.h in OpenGL instead of GL..
putting it all gtkgl.h makes it a little easier, but requires gtkgl.h to
be included in the install and by grits.h.
Andy Spencer [Sat, 15 Oct 2011 06:20:43 +0000 (06:20 +0000)]
Add mouse, keyboard, and motion events to GritsObject
These work by chaining the event from GritsOpenGL up to each individual
object, which then emits the callback if it is currently selected
(moused over).
Andy Spencer [Sat, 15 Oct 2011 06:13:39 +0000 (06:13 +0000)]
Add mouse enter/leave signals to objects
This uses the OpenGL Selection render mode to determine which objects
the mouse is over. It requires fairly tight integration between
GritsOpenGL and GritsObject.
The signal code is handled internally by GritsObject. However, most of
the actual selection matching work is done by GritsOpenGL.
Object types that wish to improve performance can implement the pick()
function in addition to the draw() function. The pick function is used
when performing selection matching. It works similar to draw, but does
not need to do textures/lighting/opacity/etc.
Andy Spencer [Sat, 18 Jun 2011 22:10:17 +0000 (22:10 +0000)]
Change binaries to shared objects
There's a double load of the GObjects when using static libraries with
plugins. Shared libraries avoid this, I think there are other work
arounds that let static binaries work too, but this should be fine for
now.
Andy Spencer [Tue, 7 Jun 2011 08:43:32 +0000 (08:43 +0000)]
Switch from GtkGLExt to internal OpenGL handling
GtkGLExt has many problems:
- It's code is bloated and convoluted
- It doesn't work on Win32
- It doesn't work with gtk+-3.0
- The last release was in early 2006
Using our own lets us fix these issues and should be easier to maintain
than trying to figure out the GtkGLExt mess, or waiting for someone else
to fix it.