mawillia

11-28-2003, 04:40 AM

Hello,

I am working on a scientific visualization program to display map of polar data using color as the Z-dimension (like a topo-map). I have selected OpenGL using an Orthographic projection and I am constructing the map using a combination of TRI_FAN and TRI_STRIP primitives having color coded indices (sample code below).

Everything works great if I leave the coordinates of the projection matrix "large" (or zoomed out); e.g., I am viewing the entire polar map of data. But if I try to reduce the bounds of the projection matrix or effectively, to zoom in on some area - say the upper quadrant of the map - I start seeing what look like rendering problems. I will observe black triangles and the edges of the map become very odd. The distortion doesn't appear to be be quantization/rounding artifacts.

I've tried various hardware configurations, and the results are similar -- it's not a driver thing, so I am thinking it's gotta be my code. I suspect I am missing some initialization twiddling, but I can't figure out what. Any insight would be extremely appreciated, as I am getting ready to punt OpenGL and try something less open source-ish.

Thanks,

-Mike

/**

* \brief Draws a blue circle of NumDiv angular segments

* with NumRings radius segments. The shade of

* blue gets more intense as you step out in radius.

*/

void

MapView: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawColorWheel(int NumDiv, int NumRings)

{

int index, index1;

float Radius = 1.0;

float x;

float y;

float ColorFactor = 1.0/((float)NumRings);

// Draw inner ring

glBegin(GL_TRIANGLE_FAN);

glColor3f(0.0f,0.0f,0.0f);

glVertex3f(0.0f,0.0f,0.0f);

glColor3f(0.0f,0.0f,ColorFactor);

for (index = 0; index <= NumDiv; index++)

{

x = sin(2.0*M_PI*(float)index/((float)NumDiv));

y = cos(2.0*M_PI*(float)index/((float)NumDiv));

glVertex3f(x,y,0.0);

}

glEnd();

// Draw the outer range segments as a series of cirular strips

for (index1 = 1; index1 < NumRings; index1++)

{

glBegin(GL_TRIANGLE_STRIP);

for (index = 0; index <= NumDiv; index++)

{

// handle wrap-around to make exactly match first points

if (index == NumDiv)

{

x = sin(2.0*M_PI*0.0/((float)NumDiv));

y = cos(2.0*M_PI*0.0/((float)NumDiv));

}

else

{

x = sin(2.0*M_PI*(float)index/((float)NumDiv));

y = cos(2.0*M_PI*(float)index/((float)NumDiv));

}

glColor3f(0.0f,0.0f,(float)(index1+1)*ColorFactor) ;

glVertex3f((Radius+1.0)*x,(Radius+1.0)*y,0.0);

glColor3f(0.0f,0.0f,(float)index1*ColorFactor);

glVertex3f(Radius*x,Radius*y,0.0);

}

glEnd();

Radius += 1.0;

}

}

/**

* \brief Handle resize event

*/

void

MapView::resizeEvent( QResizeEvent* e)

{

glViewport(0, mcLastPixmap.height()-e->size().height(), (GLsizei) e->size().width(), (GLsizei) e->size().height());

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

// msMMinX, etc. are the desired "zoom" coordinates that I want to see

// works great with msMMinX, etc. fairly large, works poorly with

// values "small" (covering maybe 100 triangles or less) from above

// +/- 100 z is intended for future clipping of "overlay" data

glOrtho(msMMinX, msMMaxX, msMMinY, msMMaxY, -100.0, 100.0);

glMatrixMode(GL_MODELVIEW);

}

/**

* Draw the map. This method is always called with the

* MODELVIEW_MATRIX selected.

*/

void MapView::drawMap()

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glLoadIdentity();

DrawColorWheel(64, 20);

glFinish();

glFlush();

}

I am working on a scientific visualization program to display map of polar data using color as the Z-dimension (like a topo-map). I have selected OpenGL using an Orthographic projection and I am constructing the map using a combination of TRI_FAN and TRI_STRIP primitives having color coded indices (sample code below).

Everything works great if I leave the coordinates of the projection matrix "large" (or zoomed out); e.g., I am viewing the entire polar map of data. But if I try to reduce the bounds of the projection matrix or effectively, to zoom in on some area - say the upper quadrant of the map - I start seeing what look like rendering problems. I will observe black triangles and the edges of the map become very odd. The distortion doesn't appear to be be quantization/rounding artifacts.

I've tried various hardware configurations, and the results are similar -- it's not a driver thing, so I am thinking it's gotta be my code. I suspect I am missing some initialization twiddling, but I can't figure out what. Any insight would be extremely appreciated, as I am getting ready to punt OpenGL and try something less open source-ish.

Thanks,

-Mike

/**

* \brief Draws a blue circle of NumDiv angular segments

* with NumRings radius segments. The shade of

* blue gets more intense as you step out in radius.

*/

void

MapView: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawColorWheel(int NumDiv, int NumRings)

{

int index, index1;

float Radius = 1.0;

float x;

float y;

float ColorFactor = 1.0/((float)NumRings);

// Draw inner ring

glBegin(GL_TRIANGLE_FAN);

glColor3f(0.0f,0.0f,0.0f);

glVertex3f(0.0f,0.0f,0.0f);

glColor3f(0.0f,0.0f,ColorFactor);

for (index = 0; index <= NumDiv; index++)

{

x = sin(2.0*M_PI*(float)index/((float)NumDiv));

y = cos(2.0*M_PI*(float)index/((float)NumDiv));

glVertex3f(x,y,0.0);

}

glEnd();

// Draw the outer range segments as a series of cirular strips

for (index1 = 1; index1 < NumRings; index1++)

{

glBegin(GL_TRIANGLE_STRIP);

for (index = 0; index <= NumDiv; index++)

{

// handle wrap-around to make exactly match first points

if (index == NumDiv)

{

x = sin(2.0*M_PI*0.0/((float)NumDiv));

y = cos(2.0*M_PI*0.0/((float)NumDiv));

}

else

{

x = sin(2.0*M_PI*(float)index/((float)NumDiv));

y = cos(2.0*M_PI*(float)index/((float)NumDiv));

}

glColor3f(0.0f,0.0f,(float)(index1+1)*ColorFactor) ;

glVertex3f((Radius+1.0)*x,(Radius+1.0)*y,0.0);

glColor3f(0.0f,0.0f,(float)index1*ColorFactor);

glVertex3f(Radius*x,Radius*y,0.0);

}

glEnd();

Radius += 1.0;

}

}

/**

* \brief Handle resize event

*/

void

MapView::resizeEvent( QResizeEvent* e)

{

glViewport(0, mcLastPixmap.height()-e->size().height(), (GLsizei) e->size().width(), (GLsizei) e->size().height());

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

// msMMinX, etc. are the desired "zoom" coordinates that I want to see

// works great with msMMinX, etc. fairly large, works poorly with

// values "small" (covering maybe 100 triangles or less) from above

// +/- 100 z is intended for future clipping of "overlay" data

glOrtho(msMMinX, msMMaxX, msMMinY, msMMaxY, -100.0, 100.0);

glMatrixMode(GL_MODELVIEW);

}

/**

* Draw the map. This method is always called with the

* MODELVIEW_MATRIX selected.

*/

void MapView::drawMap()

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glLoadIdentity();

DrawColorWheel(64, 20);

glFinish();

glFlush();

}