Jump to content
  • Advertisement
Sign in to follow this  
steelblob

Copying buffers?

This topic is 3662 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

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

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!