Copying buffers?

Started by
5 comments, last by steelblob 15 years, 4 months ago
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.
Advertisement
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 steelblob
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.
This 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:
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 )

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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]
http://www.opengl.org/wiki/index.php/Common_Mistakes#Creating_a_Texture
http://www.opengl.org/wiki/index.php/Common_Mistakes#Updating_A_Texture
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by steelblob
@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.
My 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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I figured out what I did wrong, but now the image on the cubemap appears to be very grainy and pixelated. I've increased the resolution but it still looks the same. Any way of fixing that?

This topic is closed to new replies.

Advertisement