I would imagine that if you get the screen coordinates of your sun w/ gluProject, then change the projection matrix to an orthogonal projection (and use glPushMatrix to save your perspective matrix) w/ a pixel separation of 1 unit, then you can do your lens flare as if you where working in 2D and in screen coordinates and return to your perspective projection w/ glPopMatrix.

here is the source actually :

proto of gluProject :

int gluProject(GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz);

Map the specified object coordinates (objx, objy, objz) into window coordinates, using transformations defined by a modelview matrix (modelMatrix), projection matrix (projMatrix), and viewport (viewport). The resulting window coordinates are returned in winx, winy, and winz. The function returns GL_TRUE, indicating success, or GL_FALSE, indicating failure.

(taken from somewhere at http://helios.scripps.edu/cgi-bin/infosr…OpenGL_PG/6635))

The code would be:

GLint viewport[4];

glGetIntegerv(GL_VIEWPORT, viewport); // for use in gluProject

gluProject(…);

GLint saved_matrix_mode[1];

glGetIntegerv(GL_MATRIX_MODE, saved_matrix_mode);

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

gluOrtho2D(0.0, (GLfloat) viewport[2], 0.0, (GLfloat) viewport[3]);

// do your 2D lens flare here using winx, winy, winz for the screen coord of the sun !

glPopMatrix();

glMatrixMode(saved_matrix_mode[0]);

See what I mean ?

Moz