Hello Everybody,
I am trying to calculate the position of a light using gluProject(…). However, I am having a problem obtaining the matrices required by the function call. Here is my code:
////////////////////////////////////////////////////////////////////
///!\brief renders the light map to the pixel data
///convert the lights position to screen coordinates, store this data
///read the pixel data at the position of the light
///manipulate the data using the light map
///set the rasterpos to be at the positon on screen
///draw the pixel array into memory
////////////////////////////////////////////////////////////////////
bool Render()
{
GLdouble x = myPosition.left;
GLdouble y = myPosition.top;
GLdouble z = 0;
//window coordinents
GLdouble wx = 0;
GLdouble wy = 0;
GLdouble wz = 0;
GLdouble* Model = 0, *Projection = 0;
GLint* View = 0;
//get the current active matrices
glMatrixMode(GL_MODELVIEW);
glGetDoublev (GL_MODELVIEW_MATRIX, Model);
glMatrixMode(GL_PROJECTION);
glGetDoublev (GL_PROJECTION_MATRIX, Projection);
glMatrixMode(GL_VIEWPORT);
glGetIntegerv(GL_VIEWPORT, View);
//calculate the screen space components
if(gluProject(x, y, z, Model, Projection, View, &wx, &wy, &wz) != GL_TRUE)
return false;
//check if the window positions are outside the window coordinates
if(wx < 0 || wx >= 800)
return false;
else if(wy < 0 || wy >= 600)
return false;
//obtain the pixels at the location
char* Pixel = 0;
GLint px = (GLint)x;
GLint py = (GLint)y;
GLsizei width = (GLsizei)myPosition.width;
GLsizei height = (GLsizei)myPosition.height;
glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, Pixel);
//add the lightmap values to the current pixels
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
Pixel[(width*y)+x] += LightMap->GetValue(x,y);
}
}
//move the raster pointer
glRasterPos2d(x, y);
//copy the memory
glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, Pixel);
//retrun true lol
return true;
};
I am using SFML, and since SFML does a lot of work for you, I am not very familiar with OpenGL at all. As far as I am concerned, the whole thing could be wrong.
Any help would be appreciated.