Jump to content
  • Advertisement
Sign in to follow this  
xerodsm

Cubemap Textures

This topic is 3782 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've tried searching numerous times but unfortunately I haven't had any luck. I'm trying to create a simple ray-tracer using GLSL and so far I have been able to create dynamic cubemaps for certain objects and store them as textures. My question is, how do I take my GL_TEXTURE_2D texture and set it to one of the cubemap textures, like GL_TEXTURE_CUBE_MAP_POSITIVE_X. All the cubemap examples I've seen use "glTexImage2D" but I don't have the pixel data because it's already loaded into a texture. If anyone knows how to get the pixel data from a texture I could use that too. Any other suggestions are welcome. I use: glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, size, size, 0); to create the cubemap textures, six of them. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by xerodsm
I've tried searching numerous times but unfortunately I haven't had any luck. I'm trying to create a simple ray-tracer using GLSL and so far I have been able to create dynamic cubemaps for certain objects and store them as textures. My question is, how do I take my GL_TEXTURE_2D texture and set it to one of the cubemap textures, like GL_TEXTURE_CUBE_MAP_POSITIVE_X. All the cubemap examples I've seen use "glTexImage2D" but I don't have the pixel data because it's already loaded into a texture. If anyone knows how to get the pixel data from a texture I could use that too. Any other suggestions are welcome.

I use:
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, size, size, 0);

to create the cubemap textures, six of them.

Thanks in advance.
You could use the GL_ARB_pixel_buffer_object (PBO) extension to transfer the texel data from one texture into another without needing to copy it to system RAM first, but why not just create the textures as the sides of the cubemap face to begin with? Look at the valid values of target for glCopyTexImage2D.

Share this post


Link to post
Share on other sites
You can actually use FBO extension to render 3D model directly onto a cubemap face. You don't have to do any copy at all.

Share this post


Link to post
Share on other sites
I realize all this but say I have two objects that both use cubemaps. In order to generate the cubemaps I have to render from the objects perspectives in the + and - x,y and z axes. To do that I have to clear the screen and if I do that I lose all the rendered data. What I want to do is render to a texture, save the textures in the objects class so when I'm ready to render the objects I have all the cubemap information in textures that I can just copy over. Otherwise if I just render straight to the cubemap then I will only have information about one object's cubemap saved at any given time.

Share this post


Link to post
Share on other sites
Quote:
Original post by xerodsm
...
Otherwise if I just render straight to the cubemap then I will only have information about one object's cubemap saved at any given time.
I don't see why you would have that problem. You can use an FBO to render directly to the sides of one cubemap, and then render directly to the sides of the second cubemap; there's no reason you can't keep the first cubemap intact while you render to the second one.

Some light reading.

Share this post


Link to post
Share on other sites
Maybe I'm misinterpreting something, but here's how it works now and here's why I want to do it by holding the textures...

So lets say I have two sphere objects that need to have cubemaps:

sphere 1
- generate cubemap (to do this I have to clear the buffer)
- attach cubemap to texture
- draw sphere with appropriate cubemap

sphere 2
- generate cubemap (since I still have to clear the buffer I just cleared everything I drew with sphere1)
- attach cubemap to texture
- draw sphere with appropriate cubemap

Now the only thing I see is sphere two because I just cleared the buffer when I was trying to draw my cubemap for sphere two.

If I create all the cubemaps and hold them in textures then all I have to do is somehow set the cubemap texture data equal to the texture data that I already have. Otherwise how do I generate my cubemaps without clearing the screen and not being able to see anything I drew before generating the map?

Share this post


Link to post
Share on other sites
Quote:
Original post by xerodsm
sphere 1
- generate cubemap (to do this I have to clear the buffer)
- attach cubemap to texture
- draw sphere with appropriate cubemap

sphere 2
- generate cubemap (since I still have to clear the buffer I just cleared everything I drew with sphere1)
- attach cubemap to texture
- draw sphere with appropriate cubemap

How about thinking outside the box and changing the order?
- generate sphere1 cubemap (six passes, bind each to a cubemap face)
- generate sphere2 cubemap (same again)

- draw sphere1
- draw sphere2

Share this post


Link to post
Share on other sites
As far as I know you can't do that because once you bind the second cube values to the cubemap then the first cubemap's values are gone... right? So the second one would have the same maps as the first one.

Share this post


Link to post
Share on other sites
I actually do have it in that order right now and it works in terms of creating the right textures for each cubemap, just the overwriting is the problem I'm running into.

Share this post


Link to post
Share on other sites
Quote:
Original post by xerodsm
I actually do have it in that order right now and it works in terms of creating the right textures for each cubemap, just the overwriting is the problem I'm running into.


You are using glBindTexture etc., aren't you?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!