Copying buffers?
I am working on a project that involves mapping an environmental map to a cubemap and rendering applying it to a series of objects. Attaching the cubemap to an object isn't a problem (with temp textures).
The problem comes when I need get an image of the environment and store it to a variable of QImage type. I have to do this six times, once for each side of the cube.
Logically, the easiest method that comes to mind is I can rotate the camera 6 different directions before rendering and apply the textures to the box.
I tried using glCopyTexImage2D to copy a 512x512 image, but it didn't work and it created a noticeable lag.
Another idea would to be use the frame buffer if GL_EXT_framebuffer_object is supported, but I can't find any comprehendible code utilizing frame buffers.
Any help would be appreciated.
Quote:Original post by steelblob
Another idea would to be use the frame buffer if GL_EXT_framebuffer_object is supported, but I can't find any comprehendible code utilizing frame buffers.
Read OpenGL FrameBuffer Object 101 and OpenGL FrameBuffer Object 201 .
Quote:Original post by steelblobThis doesn't make much sense, especially if you mean QT's QImage. Ideally, you should be creating a single 512x512 cubemap texture, and then rendering and copying in each face in turn - something like this:
The problem comes when I need get an image of the environment and store it to a variable of QImage type. I have to do this six times, once for each side of the cube.
glGenTextures(1, &texture_id)for i in range(6): DrawScene( camera ) glBindTexture( GL_CUBEMAP_X + i, texture_id ) glCopyTexImgae2D( GL_CUBEMAP_X + i, 0, GL_RGBA, 0, 0, 512, 512, 0 )
Yes, I am using QT. I cannot use GLUT.
Code:
--------
vector<QImage> ImageIndex;
QImage buffer(512, 512, QImage::Format_ARGB32 );
buffer.fill(qRgba(0,255,255,255));
ImageIndex[CUBE_NEG_Z] = QGLWidget::convertToGLFormat(buffer);
... for all the other images in the index
for (int i = 0; i < 6; i++)
{
glTexImage2D( cubefaces, 0, GL_RGBA8, ImageIndex.width(), ImageIndex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ImageIndex.bits());
}
--------
Basically I create an image and store it to the index.
I tried using:
--------
bindTexture(temp, GL_TEXTURE_2D);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
--------
But it didn't seem to do anything.
@swiftcoder, your code doesn't look like it will work with my code; I don't see how I could store the buffer to a QImage so I could utilize it with my code.
[Edited by - steelblob on November 29, 2008 8:56:20 PM]
Code:
--------
vector<QImage> ImageIndex;
QImage buffer(512, 512, QImage::Format_ARGB32 );
buffer.fill(qRgba(0,255,255,255));
ImageIndex[CUBE_NEG_Z] = QGLWidget::convertToGLFormat(buffer);
... for all the other images in the index
for (int i = 0; i < 6; i++)
{
glTexImage2D( cubefaces, 0, GL_RGBA8, ImageIndex.width(), ImageIndex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ImageIndex.bits());
}
--------
Basically I create an image and store it to the index.
I tried using:
--------
bindTexture(temp, GL_TEXTURE_2D);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
--------
But it didn't seem to do anything.
@swiftcoder, your code doesn't look like it will work with my code; I don't see how I could store the buffer to a QImage so I could utilize it with my code.
[Edited by - steelblob on November 29, 2008 8:56:20 PM]
http://www.opengl.org/wiki/index.php/Common_Mistakes#Creating_a_Texture
http://www.opengl.org/wiki/index.php/Common_Mistakes#Updating_A_Texture
http://www.opengl.org/wiki/index.php/Common_Mistakes#Updating_A_Texture
Quote:Original post by steelblobMy question is why you think you need to store it into a QImage? Reading back the rendered image from the GPU into a buffer in main memory is a very expensive operation, and since all you want to do is render into the six faces of a cubemap, OpenGL already lets you do this, entirely on the GPU.
@swiftcoder, your code doesn't look like it will work with my code; I don't see how I could store the buffer to a QImage so I could utilize it with my code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement