PDA

View Full Version : Trouble with Orthographic Projection



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();
}

mawillia
11-28-2003, 04:58 AM
Oh yeah, forgot the snippet from initialization...

-Mike




glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

Relic
11-28-2003, 08:16 AM
Nothing obvious.
You are aware that your triangle fan faces faces are clockwise and the the strips are CCW? OpenGL's default for frontface is counterclockwise so you're looking at some backfaces.
I normally use cos() for x and sin() for y and mathematically positive rotation is counter clockwise.
Try if it helps to change the face calculation to ccw.

[This message has been edited by Relic (edited 11-28-2003).]

mawillia
11-28-2003, 04:17 PM
Sadly, I have found the problem. My code is rendering to a pixmap through a QT [www.trolltech.com] GLContext Widget. I am running on windows XP, and if I change my "hardware acceleration" settings on my display settings to disable cursor and bitmap accelerations, everything works "perfectly".

(Relic: thanks for the CCW/CW catch. BTW, the backwards angle is because this app is for radar data, which historically defines azimuth as clockwise sweep from north or "up".)

-Mike