Jump to content

[C++] Texture::GetPixels() for buffer texture


Rastar
 Share

Recommended Posts

Yes, that works. But I am trying to get the content of a render buffer

 

Texture* tex = Texture::Create(width, height);
Buffer* buffer = Buffer::Create(width, height, 1, 0);
buffer->SetColorTexture(tex);
buffer->Enable();
buffer->Clear();
world->Render();
buffer->Disable();
Context::SetCurrent(context);
tex = buffer->GetColorTexture();
const char* pixelBuf = new char[tex->GetMipmapSize(0)];
tex->GetPixels(pixelBuf);

 

A call to mat->SetTexture(tex) works, probably because the texture handle is being passed, but the above call to GetPixels() doesn't. As I said, I assume the texture isn't actually retrieved from the GPU to the main memory.

Link to comment
Share on other sites

Forgive me if I'm wrong, but I think your problem may be the const

const char* pixelBuf = new char[tex->GetMipmapSize(0)];
tex->GetPixels(pixelBuf);

When I did this, I had to cast it

GLubyte* tPixels = new GLubyte[tex->GetMipmapSize(0)];
tex->GetPixels(reinterpret_cast<const char*>(tPixels));

 

I have no idea why it's passed as a const char* since it's obviously modified; if anything, it should be passed as a char* const.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...