Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: gluProject matrix problems

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013

    Lightbulb gluProject matrix problems

    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:

    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 =;
    		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
    		glGetDoublev (GL_MODELVIEW_MATRIX,  Model);
    		glGetDoublev (GL_PROJECTION_MATRIX, Projection);
    		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.

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2013
    Well, what i was doing was not declaring matrices to send to gluProject. It runs, but the output is not what i intended.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts