Hello, everyone.
I'm using OpenGL to draw some weather radar data to the screen, and the glDrawArrays() function is producing some strange results. What it is supposed to do is draw triangle strips with x and y as the longitude and latitude of the point and z as proportional to the value returned from the radar. The polygons are then textured to make the color fade from blue to green to yellow to red as the z values get bigger. I'll include some stripped down code:
Code:
/* radar.cxx */
void Radar::Draw()
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTranslatef(-c_center_point.lon, -c_center_point.lat, -depth);
glVertexPointer(3, GL_FLOAT, 0, m_vertex_array);
glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexImage1D( GL_TEXTURE_1D, 0, 3, m_texture.width(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, m_texture.bits() );
glTexCoordPointer(1, GL_FLOAT, 0, m_texture_array);
glDrawArrays(GL_TRIANGLE_STRIP, 0, m_vertex_cnt);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void Radar::CreateVertexArray()
{
int width, height, offset;
int cnt = 0;
int tex_cnt = 0;
// Pointer to a 2-dimensional array of RadarDataPoint structs,
// containing a latitude, a longitude, and a value.
RadarDataPoint ***data_grid;
double isovalue;
// Fill the grid with data
m_interface->get_lat_lon_data(data_grid);
// Put data grid dimensions into the variables
m_interface->get_dimensions(width, height, offset);
if (m_texture_array)
{
delete[] m_texture_array;
}
if (m_vertex_array)
{
delete[] m_vertex_array;
}
m_old_data_height = m_data_height;
m_data_width = width;
m_data_height = height;
m_vertex_array = new float[m_data_width * m_data_height * 3];
m_texture_array = new float[m_data_width * m_data_height * 2];
for(int jdy = 0; jdy < m_data_height; jdy++)
{
for(int idx = offset; idx < offset + m_data_width; idx++)
{
// Because idx represents the radial of the radar, wrap around to 0
// if it becomes greater than 359
int use_idx = (idx>=360 ? idx-360 : idx);
// Filter out any invalid data points
if ((*data_grid)[use_idx][jdy].lat != 0.0 &&
(*data_grid)[use_idx][jdy].lon != 0.0)
{
isovalue = ((*data_grid)[use_idx][jdy].value<-10.0 ? -10.0 :
(*data_grid)[use_idx][jdy].value);
isovalue /= 15.0;
m_vertex_array[cnt ] = (*data_grid)[use_idx][jdy].lon;
m_vertex_array[cnt + 1] = (*data_grid)[use_idx][jdy].lat;
m_vertex_array[cnt + 2] = isovalue;
m_texture_array[tex_cnt] = isovalue / 2.0;
cnt+=3;
tex_cnt++;
}
}
}
m_vertex_cnt = cnt / 3;
}
Those places are more than likely where the problem is. Attached is an image of what results. What it appears to me it's doing is taking a vertex or two and drawing triangles from the zero plane to those points. The normals of the triangles are either pointed toward or away from the radar site.
Some notes:
1. The data is valid. I didn't go through all of it because there is a bunch of it, and it would take all day. At first glance, it appears valid.
2. The texture and vertex arrays are initialized to NULL.
If you need any background information on weather radar: http://en.wikipedia.org/wiki/NEXRAD
Thanks in advance for any help.