Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: glReadPixels and glDrawPixels with GL_LUMINANCE

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    7

    glReadPixels and glDrawPixels with GL_LUMINANCE

    Hello,

    I am trying to manipulate the luminance at a pixels given location, but I cannot understand a couple of things. How come the target area tends to be blue?

    How can I remove the outline of the area being rendered upon?

    Code :
    bool Render()
    	{
    		GLdouble x = myPosition.left;
    		GLdouble y = myPosition.top;
    		GLdouble z = 1;
     
    		//window coordinents
    		GLdouble wx = 0;
    		GLdouble wy = 0;
    		GLdouble wz = 0;
     
    		GLdouble Model[16];
    		GLdouble Projection[16];
    		GLint    View[4];
     
    		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 positons 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
     
    		GLint px = (GLint)x;
    		GLint py = (GLint)y;
     
    		GLsizei width  = (GLsizei)myPosition.width;
    		GLsizei height = (GLsizei)myPosition.height;
     
    		unsigned char* Pixel = new unsigned char[(width)*(height)];
     
    		glReadPixels(x, y, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, Pixel);
     
    		//add the lightmap values to the current pixels
     
    		int bufpos = 0;
    		float lmv = 0;
     
    		int R = 0, G = 0, B = 0;
    		for(int y = 0; y < height; y++)
    		{
    			for(int x = 0; x < width; x++)
    			{
    				bufpos = (width*y) + x;
    				lmv = LightMap->Map[y][x];
     
    				//if(lmv > 0.0666667)
    					Pixel[bufpos] *= lmv;
    			}
    		}
    		//move the raster pointer
    		glRasterPos2d(wx, wy);
     
    		//copy the memory
    		glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, Pixel);
     
    		delete[] Pixel;		
     
    		//retrun true lol
    		return true;
    	};

    This looks okay, but there is a noticeable border, and the color is blue.


    this one just sucks.


    any help is appreciated.
    Last edited by pogrady; 02-06-2013 at 06:08 PM. Reason: Changed title

Posting Permissions

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