PDA

View Full Version : auxiliary buffers



Selina
05-19-2010, 05:47 PM
Hi
I am trying to create auxiliary buffers but I got errors like these ones:

error C3861: 'glGenBuffers': identifier not found
error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
error C3861: 'glBindBuffer': identifier not found

I added the headers: glew.h , glext.h , and wglext.h
Also, GL/glut.h is included

The functions are declaired in the included files, but not defined anywhere. Can anyone tell me how to use these functions? and how to set an index buffer ?
Your help would be highly appreciated


.

ZbuffeR
05-21-2010, 05:33 AM
AUX buffers are very deprecated, are rarely supported anyway.
Are you really sure you need to use AUX ?
And not a framebuffer object for example ?

Selina
05-21-2010, 11:51 AM
AUX buffers are very deprecated, are rarely supported anyway.
Are you really sure you need to use AUX ?
And not a framebuffer object for example ?

Thank you for reply.
Actually I am trying to draw parts of the screen rendered by opengl. So I received an advice from this site to draw the parts as texture in quad portions. I used glReadPixels() to read the frame buffer and draw it as texture but the resulting image was just the texture image i already loaded to the program. Also I used the windows function:

COLORREF pixel = GetPixel( GetDC( NULL ), ip, jp);

But the same result, it gave me the bmp texture file and not the image itself.

I need just a way to read the pixels colors from the screen and save the portion I need to draw in an auxiliary buffer or any other buffer I can draw (drawable buffer). I used glDrawPixels() did not work with the available buffers(front and back).
Now, I am desperately looking for a piece of software to capture the screen and read the colors of the pixels and then I will need an auxiliary buffer or another drawable one to draw selected portions of the image. There are many commercial screen capturers or grabber software but I can not employ them in my software, I need it to be embedded in my program


I would really appreciate any help


This is my simple function:


void MyFunction()
{

int width_p = 600;
int height_p = 600;


float VCorners[4][3] = {{ 0.0f, 0.0f, -1.0f }, // left bottom

{ 8.5f, 0.0f, -1.0f }, //right bottom

{ 8.5f, 8.5f, -1.0f }, // right top

{ 0.0f, 8.5f, -1.0f }}; // left top



float percentage;
float* pixels_index = new float[3*(width_p)*(height_p)];

int ip,jp;



for (jp=0;jp<height_p;jp++)
{

percentage=jp/height_p;

cout<< percentage <<"\n";

for (ip=0;ip<width_p;ip++)
{
COLORREF pixel = GetPixel( GetDC( NULL ), ip, jp);
pixels_index[3*(width_p*jp + ip)] = (int)GetRValue( pixel );
pixels_index[3*(width_p*jp + ip)+1] = (int)GetGValue( pixel );
pixels_index[3*(width_p*jp + ip)+2] = (int)GetBValue( pixel );
}
}


//glReadBuffer(GL_FRONT_RIGHT);
//glPixelStorei(GL_PACK_ALIGNMENT, 1);
//glReadPixels(0,0,600,600,GL_RGB,GL_FLOAT, pixels_index);

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 100, 100, 0, GL_FLOAT, GL_FLOAT, pixels_index);



glEnable (GL_TEXTURE_2D);

glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0); glVertex3fv(VCorners[0]);
glTexCoord2f (1.0, 0.0); glVertex3fv(VCorners[1]);
glTexCoord2f (1.0, 1.0); glVertex3fv(VCorners[2]);
glTexCoord2f (0.0, 1.0); glVertex3fv(VCorners[3]);
glEnd ();

glDisable (GL_TEXTURE_2D);




glutSwapBuffers();
glFlush();
delete [] pixels_index;

}

Dan Bartlett
05-21-2010, 03:42 PM
One thing I notice is that you're using:


glReadBuffer(GL_FRONT_RIGHT);

Front right + back right buffers only exist if you have a stereo setup.
The default value is GL_FRONT in single buffered apps + GL_BACK in double buffered apps, which refer to the front left + back left buffers.

http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml

Selina
05-21-2010, 07:27 PM
One thing I notice is that you're using:


glReadBuffer(GL_FRONT_RIGHT);

Front right + back right buffers only exist if you have a stereo setup.
The default value is GL_FRONT in single buffered apps + GL_BACK in double buffered apps, which refer to the front left + back left buffers.

http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml

thank you for reply
I tried all the buffers and did not work, for this code the values I got from the front left buffer were all zeroed:

glReadBuffer(GL_FRONT_LEFT);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0,0,20,20,GL_RGB,GL_FLOAT, pixels_index);

for (int it=0;it<100;it++){
cout<< pixels_index[it] <<"//"<< pixels_index[it+1] <<"//"<<pixels_index[it+2]<<"\n";
}

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

.

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 20, 20, 0, GL_RGB, GL_FLOAT, pixels_index);

Dan Bartlett
05-22-2010, 05:09 AM
You use GL_FLOAT in glReadPixels, but if you're using the default framebuffer, it's most likely a single byte per color component, so it may be better to use GL_UNSIGNED_BYTE.

Are you sure you're reading from the correct area of the framebuffer? glReadPixels works from the lower left corner, so you might need (x, height - y) if you want to read a rectangle from the upper left corner.

Another possibility (although unlikely) is that you have a buffer bound to GL_PIXEL_PACK_BUFFER, then when using glReadPixels, data is being copied to that buffer instead, using the last argument as an offset into buffer, rather than as a pointer in client memory.
If you have a buffer bound to GL_PIXEL_UNPACK_BUFFER, then when using glTexImage2D, the data will come from that buffer.

Copying via PBOs should be faster than using client memory, but if you are just capturing the framebuffer into a texture, and not doing any modifications, then instead of using glReadPixels/glTexImage2D you could use:


glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB {or GL_RGBA?}, 0, 0, 20, 20, 0);

Another alternative would be to use FBOs + render-to-texture to render directly to textures rather than to framebuffer then reading back, but your target hardware will need to support this.
http://www.songho.ca/opengl/gl_fbo.html#example

You could also have issues with mipmapping, if you have valid values in pixels_index after calling glReadPixels, but nothing displays on screen, then does generating all mipmap levels work?


glTexParameteri(target, GL_GENERATE_MIPMAP{_SGIS}, GL_TRUE); // requires OpenGL 1.4+ {or GL_SGIS_generate_mipmap}, deprecated in OpenGL 3.0+
or
glGenerateMipmap{EXT}(GL_TEXTURE_2D); // requires OpenGL 3.0 or GL_ARB_framebuffer_object {or GL_EXT_framebuffer_object}

Selina
05-22-2010, 06:57 AM
You use GL_FLOAT in glReadPixels, but if you're using the default framebuffer, it's most likely a single byte per color component, so it may be better to use GL_UNSIGNED_BYTE.

Are you sure you're reading from the correct area of the framebuffer? glReadPixels works from the lower left corner, so you might need (x, height - y) if you want to read a rectangle from the upper left corner.

Another possibility (although unlikely) is that you have a buffer bound to GL_PIXEL_PACK_BUFFER, then when using glReadPixels, data is being copied to that buffer instead, using the last argument as an offset into buffer, rather than as a pointer in client memory.
If you have a buffer bound to GL_PIXEL_UNPACK_BUFFER, then when using glTexImage2D, the data will come from that buffer.

Copying via PBOs should be faster than using client memory, but if you are just capturing the framebuffer into a texture, and not doing any modifications, then instead of using glReadPixels/glTexImage2D you could use:


glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB {or GL_RGBA?}, 0, 0, 20, 20, 0);

Another alternative would be to use FBOs + render-to-texture to render directly to textures rather than to framebuffer then reading back, but your target hardware will need to support this.
http://www.songho.ca/opengl/gl_fbo.html#example

You could also have issues with mipmapping, if you have valid values in pixels_index after calling glReadPixels, but nothing displays on screen, then does generating all mipmap levels work?


glTexParameteri(target, GL_GENERATE_MIPMAP{_SGIS}, GL_TRUE); // requires OpenGL 1.4+ {or GL_SGIS_generate_mipmap}, deprecated in OpenGL 3.0+
or
glGenerateMipmap{EXT}(GL_TEXTURE_2D); // requires OpenGL 3.0 or GL_ARB_framebuffer_object {or GL_EXT_framebuffer_object}


thank you very much Dan
These are interesting information. I will check them and try all your suggestions and come back to tell about the outcome. I think I missed to generate mipmap.
Thank you again. I appreciate it.


.

Selina
05-25-2010, 06:48 PM
You use GL_FLOAT in glReadPixels, but if you're using the default framebuffer, it's most likely a single byte per color component, so it may be better to use GL_UNSIGNED_BYTE.

Are you sure you're reading from the correct area of the framebuffer? glReadPixels works from the lower left corner, so you might need (x, height - y) if you want to read a rectangle from the upper left corner.

Another possibility (although unlikely) is that you have a buffer bound to GL_PIXEL_PACK_BUFFER, then when using glReadPixels, data is being copied to that buffer instead, using the last argument as an offset into buffer, rather than as a pointer in client memory.
If you have a buffer bound to GL_PIXEL_UNPACK_BUFFER, then when using glTexImage2D, the data will come from that buffer.

Copying via PBOs should be faster than using client memory, but if you are just capturing the framebuffer into a texture, and not doing any modifications, then instead of using glReadPixels/glTexImage2D you could use:


glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB {or GL_RGBA?}, 0, 0, 20, 20, 0);

Another alternative would be to use FBOs + render-to-texture to render directly to textures rather than to framebuffer then reading back, but your target hardware will need to support this.
http://www.songho.ca/opengl/gl_fbo.html#example

You could also have issues with mipmapping, if you have valid values in pixels_index after calling glReadPixels, but nothing displays on screen, then does generating all mipmap levels work?


glTexParameteri(target, GL_GENERATE_MIPMAP{_SGIS}, GL_TRUE); // requires OpenGL 1.4+ {or GL_SGIS_generate_mipmap}, deprecated in OpenGL 3.0+
or
glGenerateMipmap{EXT}(GL_TEXTURE_2D); // requires OpenGL 3.0 or GL_ARB_framebuffer_object {or GL_EXT_framebuffer_object}


the ideas you suggested were just perfect, they work !

I used GL_UNSIGNED_BYTE and mipmap generation, also, had to give the texture an ID as an argument for the function:
glGenTextures(1, &amp;ID)

ZbuffeR and Dan Bartlett, Thank you very much for help.

.