Hi,
I’m trying to copy to GL_COLOR_ATTACHMENT0_EXT an array stored in CPU. To this end I use glDrawPixels after attaching glFramebufferTexture2DEXT.
The code bellow is not what I want to do but I’m testing the correctness of the code:
GLuint colorTex;
glGenTextures(1, &colorTex);
glBindTexture(GL_TEXTURE_2D, colorTex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREEN_RES_X, SCREEN_RES_Y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
GLuint fbo=0;
glGenFramebuffersEXT(1, &fbo);
//render to texture to avoid scissors test by qglwidget
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
//depth cannot be rendered without color
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,colorTex,0);
GLubyte *pixels=new GLubyte[SCREEN_RES*3];
//create a red image
for(int i=0;i<SCREEN_RES;i++)
{
pixels[i*3]=255;
pixels[i*3+1]=pixels[i*3+2]=0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawPixels(SCREEN_RES_X,SCREEN_RES_Y,GL_RGB,GL_UNSIGNED_BYTE,pixels);
GLubyte * color=new GLubyte[SCREEN_RES*3];
glReadPixels(0,0,SCREEN_RES_X,SCREEN_RES_Y,GL_RGB,GL_UNSIGNED_BYTE,color);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
glDeleteFramebuffersEXT(1, &fbo);
glDeleteTextures(1,&colorTex);
The problem is that color is all white, like DrawPixels has no effect. Am I doing something wrong?
Thank you.