• Advertisement
Sign in to follow this  

Sub Texture

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

Hey everyone. I was just wondering if you can use an existing texture and use its sub region for texture mapping instead of the entire one without any copying or creation of new textures. Is this possible? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Yeah, but what if I have a 512x512 texture and a quad with (0, 0) -> (1, 1) texture coordinates and I want to use only half of the texture: (0, 0) -> (256, 256)?

Share this post


Link to post
Share on other sites
then you will have to adjust the texture coordinates of the quad to (0,0)->(0.5,0.5)

Share this post


Link to post
Share on other sites
No, I want to keep the texture coordinates static.
I want to actually take a piece of the texture and use it asif it was an entire one without adjusting any texture coordinates.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A solution should be to create another smaller texture and to copy the portion of the large one in the small one. But IMHO this is not very good. The right choice is to map the large original texture with the texture coordinates as said before.

Kind regards

Share this post


Link to post
Share on other sites
If you absolutely have to keep the coordinates untouched, you can transform them so they are within the desired range.

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.5, 0.5, 1);

Now the range [0, 1] is scaled to [0, 0.5].

Share this post


Link to post
Share on other sites
The thing is I am workig with Vertex Textures and I want to use a sub area of a texture untill I have to replace it with another texture. Think of it as a Radar in a RTS game. When that white box (your view port) moves to the side and reaches the edge, a new background is copied to the radar and the white box moves accordingly. Get what I'm saying? I am using it for a heightmap. Its for my year project.
If it were possible to do, would there be any speed increases since no new textures have to be created so many times?

Or how about the vertex shader?

I hope I am making sence. Sorry I'm typing in a rush.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

I hope I am making sence.

doubt it .

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
The thing is I am workig with Vertex Textures and I want to use a sub area of a texture untill I have to replace it with another texture. Think of it as a Radar in a RTS game. When that white box (your view port) moves to the side and reaches the edge, a new background is copied to the radar and the white box moves accordingly. Get what I'm saying? I am using it for a heightmap. Its for my year project.
If it were possible to do, would there be any speed increases since no new textures have to be created so many times?

Or how about the vertex shader?

I hope I am making sence. Sorry I'm typing in a rush.

Vertex Textures?

Uhm.. do you want to scroll the texture?

Quote:
If it were possible to do, would there be any speed increases since no new textures have to be created so many times?

Are you creating textures every frame??

Quote:
I hope I am making sence.

You're not making any sence at all :P :D

Share this post


Link to post
Share on other sites
Quote:
Original post by angry
Quote:
I hope I am making sence.

You're not making any sence at all :P :D


Sorry man. Had to type quick.

Quote:
Original post by angry
Are you creating textures every frame??


Almost. I have to do a lot of buffer copying to send the resulting texture to the GPU.

Quote:
Original post by angry
Uhm.. do you want to scroll the texture?


Basically yes.

I have a big buffer containing heightmap info and I have to take a sub image, make it a texture and send it to the GPU. As the camera moves I have to do this almost every frame. Still too costly though. I was hoping of creating a bigger than normal texture and tell the GPU to use only a sub part of that texture the size of what I normally wanted it to be, so when the camera moves, there should be no copying, just adjusting.

Making sence now? ;p

Share this post


Link to post
Share on other sites
Just one problem. VBOs.
I have a couple of VBO vertex and texture coords buffers. Thus it's static.
Don't tell me to resend those data to the video card. I think it will then make it 10x slower, or something. Then I could have just as well not have used VBOs.

Share this post


Link to post
Share on other sites
Perhaps it would be better not to use VBOs for that one quad you're using to display the 'radar'. Instead, render it normally and modify the texture coordinates to make it display only a small portion of your entire map.

If your problem lies in the fact that your heightmap is very large, too big to fit in one OpenGL texture, you can just break it down into a grid of smaller textures and render using those accordingly (you may have to render up to 4 quads this way, when your view is over the corner where 4 smaller subdivided squares of your minimap meet).

That way you would only need to generate the minimap texture(s) once at the beginning.

If you need to display moving objects, it might be a good idea to separate them from the background and render them separately (you could use glScissor testing), on top of the static minimap.

Those are just some ideas that come to me after reading what you've described trying to accomplish. Hope it helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Last Attacker
Just one problem. VBOs.
I have a couple of VBO vertex and texture coords buffers. Thus it's static.
Don't tell me to resend those data to the video card. I think it will then make it 10x slower, or something. Then I could have just as well not have used VBOs.


Not remotely a problem, set up the VBOs with the texture coords set to the smallest size you want to display then feed an offset into a VS and add the offset to the texture coords.

simple.

Share this post


Link to post
Share on other sites
Quote:
Original post by shurcool
Perhaps it would be better not to use VBOs for that one quad you're using to display the 'radar'. Instead, render it normally and modify the texture coordinates to make it display only a small portion of your entire map.

If your problem lies in the fact that your heightmap is very large, too big to fit in one OpenGL texture, you can just break it down into a grid of smaller textures and render using those accordingly (you may have to render up to 4 quads this way, when your view is over the corner where 4 smaller subdivided squares of your minimap meet).

That way you would only need to generate the minimap texture(s) once at the beginning.

If you need to display moving objects, it might be a good idea to separate them from the background and render them separately (you could use glScissor testing), on top of the static minimap.

Those are just some ideas that come to me after reading what you've described trying to accomplish. Hope it helps.


Thanks for your input, but I just used the radar as an illustration of what I wanted to achieve. I am using a texture for rendering my terrain. Sorry that I didn't sound very clear on the subject. I Guess I was in a little rush or something or didn't think to clearly.

After a while I thought of using the Vertex Shader, I guess I was thinking inside the box ;). Still have to implement it though, but for interrest sake... is there a way of doing this in plain OpenGL? No Shader programming "allowed" ;)

Thanks again... and sorry for the beat around the bush. I feel kinda stupid...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement