glReadPixels

Started by
5 comments, last by me_here_me 16 years, 2 months ago
Hi, I have a fragment shader that writes "gl_FragColor(0.3,0.5,0.6,0.7)" to each of the fragments. But when I retrieve the fragments in an array using: normalsMapMesh = new float[fbWidth * fbHeight * 4]; glReadPixels(0,0,fbWidth,fbHeight,GL_RGBA,GL_FLOAT,normalsMapMesh); it returns 1.0 for each alpha value. The values for the red, green and blue component are correct, its only the alpha channel which is always returned as 1.0, despite the fact that I always write 0.7 in FS. any hint on the issue !!! best wishes
Advertisement
You probably didn't request an alpha channel in the framebuffer.
Is there some method to request alpha channel in frame buffer. I am using the following code, if you can have a quick look. I used color4f through out:

	glColor4f( 1., 1., 1., 1. );	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glUseProgram(meshNormals);	glUniformMatrix4fv(glGetUniformLocation(meshNormals, "MVOldV"), 1, 0, MVOldV);	int isOnEdge;	for( unsigned int i=0; i< stlMesh.size(); i++)	{		dummy = stlMesh->getNormal();		dummyN1 = stlMesh->getNormal(1);		dummyN2 = stlMesh->getNormal(2);		dummyN3 = stlMesh->getNormal(3);		stlMesh->getVertex( 1, dummy1 );		stlMesh->getVertex( 2, dummy2 );		stlMesh->getVertex( 3, dummy3 );		isOnEdge = stlMesh->getIsOnEdge();		glUniform1i(glGetUniformLocation(meshNormals, "isOnEdge"), isOnEdge);					glUniform3f(glGetUniformLocation(meshNormals, "vertexNorm1"), -dummyN1.x, -dummyN1.y, -dummyN1.z);		glUniform3f(glGetUniformLocation(meshNormals, "vertexNorm2"), -dummyN2.x, -dummyN2.y, -dummyN2.z);		glUniform3f(glGetUniformLocation(meshNormals, "vertexNorm3"), -dummyN3.x, -dummyN3.y, -dummyN3.z);			glBegin( GL_TRIANGLES );				// vertex 1			glNormal3f( -dummyN1.x, -dummyN1.y, -dummyN1.z );			glVertex3f( dummy1.x, dummy1.y, dummy1.z );			// vertex 2			glNormal3f( -dummyN2.x, -dummyN2.y, -dummyN2.z );			glVertex3f( dummy2.x, dummy2.y, dummy2.z );		// vertex 3			glNormal3f( -dummyN3.x, -dummyN3.y, -dummyN3.z );			glVertex3f( dummy3.x, dummy3.y, dummy3.z );		glEnd();	}		glReadPixels(0,0,fbWidth,fbHeight,GL_RGBA,GL_FLOAT,normalsMapMesh);		// read whats on the framebuffer into normalsMapMesh in RGBA format
I think you have to post your window creation code.
will this help find the problem?
void COpenGLCanvas2::initializeGL() {	glewInit();	glClearColor(1, 1, 1, 1);	meshLight = loadShader("mesh-light.vs", "mesh-light.frag");	meshNormals = loadShader("mesh-Normals.vs", "mesh-Normals.frag");		// Create the first white light	glEnable( GL_LIGHTING );	glEnable( GL_LIGHT0 );	glEnable(GL_DEPTH_TEST);	glEnable(GL_CULL_FACE);	glEnable(GL_ALPHA_TEST);	glAlphaFunc(GL_ALWAYS, 0.0);	glFrontFace(GL_CW);	// Enable depth testing	glEnable( GL_DEPTH );	// Set up a shading model	glShadeModel( GL_SMOOTH );


regards
No, this won't help. As Boder said, you need to provide the code creating the OpenGL window.
thanks a lot friends.

From your discussion I got an idea that I may not be setting my display mode to RGBA. As I was using QT for drawing my openGL window so I had to enable the equivalent option in the constructor of the QGLWidget class. Had to look into API documentation for that.

anyway, thanks for help and correct hints :)

regards

This topic is closed to new replies.

Advertisement