Jump to content
  • Advertisement
Sign in to follow this  


This topic is 3959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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. );
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 );

glReadPixels(0,0,fbWidth,fbHeight,GL_RGBA,GL_FLOAT,normalsMapMesh); // read whats on the framebuffer into normalsMapMesh in RGBA format

Share this post

Link to post
Share on other sites
will this help find the problem?

void COpenGLCanvas2::initializeGL() {
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 );

glAlphaFunc(GL_ALWAYS, 0.0);

// Enable depth testing
glEnable( GL_DEPTH );
// Set up a shading model
glShadeModel( GL_SMOOTH );


Share this post

Link to post
Share on other sites
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 :)


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!