Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jiia

More newbie texture questions

This topic is 5218 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'm trying to convert my old 2D GUI engine to my new 3D editor. The skin for all controls reside in a single image. From what I do know about 3D textures (which doesn't amount to a whole bunch), they need to be sized by a power of 2. Does this mean the texture itself needs to be aligned this way, or do the U,V coordinates also have to be aligned by powers of 2? Also, do textures usually have to be square? Or is it okay to use 32x64 textures, etc? For example, can I create a 256x256 texture that contains all of my control bitmaps, then create a square mesh sized 10.0fx5.0f and assign it UV coordinates 40.0f,40.0f to 50.0f,45.0f for a check box control? Thanks for any help, and sorry to spam the board with so many questions! EDIT: Feel free to move this to another forum if it should be [edited by - Jiia on May 8, 2004 12:26:17 PM]

Share this post


Link to post
Share on other sites
Advertisement
Texture coordinates, 0.0f...1.0f, represent the whole texture size, regardless of the actual size of the texture data.
So, if you want to tile a texture two times in both U and V on a quad, set the U and V to 0 on top-left corner, and 2.0 on the lower-right corner.

Texture coordinates don't have to be powers of 2, they are just floating point numbers. The texture data itself, however, is required to be in powers of two on most cards (not on recent cards anymore, though).
Whether the textures have to be square is also hardware-dependent separately of the ^2 issue.

-Nik

[edited by - Nik02 on May 8, 2004 12:50:22 PM]

Share this post


Link to post
Share on other sites
Damn, it totally slipped my mind about the 0.0f to 1.0f UV coordinates. How would I be able to use real image coordinates that way?

Lets see.. 256.. 40th pixel.. 0.15625?? That totally sucks Wouldn''t there be extreme problems trying to set the texture coordinate to 0.15625? Or is that okay? Isn''t there an easier way to do this? How in the world can a guy have a non power-of-2, non-square shaped image shown on the screen?

How is this usually done? Are there any detailed tutorials about drawing 2D images over a 3D engine? I know the basics like creating the mesh and setting up the projection & view matrices, but a lot of what I need to do seems impossible.

Share this post


Link to post
Share on other sites
quote:
Original post by Jiia


Lets see.. 256.. 40th pixel.. 0.15625?? That totally sucks Wouldn''t there be extreme problems trying to set the texture coordinate to 0.15625? Or is that okay? Isn''t there an easier way to do this? How in the world can a guy have a non power-of-2, non-square shaped image shown on the screen?



What really is the problem? You generally know the texture size and the size of the area that you need to use from it. Just perform the division, and be happy :D
Remember, the texture coordinates are not integers, it is perfectly valid to represent a number like 0.15625 on them.

-Nik

Share this post


Link to post
Share on other sites
put your controls in one large file. every control is 256x256 big. Now you write a function which reads 256x256 big areas from this file an saves it to a direct3d texture.
so you have for every control an own texture

scio me nihil scire
Ceterum censeo, carthaginem delendam esse

Share this post


Link to post
Share on other sites
quote:
Original post by Nik02 What really is the problem? You generally know the texture size and the size of the area that you need to use from it. Just perform the division, and be happy :D
Remember, the texture coordinates are not integers, it is perfectly valid to represent a number like 0.15625 on them.
It''s not a problem, I just didn''t realize it was okay to do this. And this is not another hardware specific issue?? Sounds great, thanks for the help!

quote:
put your controls in one large file. every control is 256x256 big. Now you write a function which reads 256x256 big areas from this file an saves it to a direct3d texture.
so you have for every control an own texture
256x256 would be a bit extreme for a checkbox / mouse cursor Still, I understood your point. Thanks!

Share this post


Link to post
Share on other sites
Texture coordinates have not been hardware specific since the dawn of commercial 3d acceleration. You will not find a 3d card that doesn''t support at least one set of them (unless it is some very exotic model).

-Nik

Share this post


Link to post
Share on other sites
I''m sorry to ask so many questions, but can I throw one more in here?

Is it unheard of to modify U,V coordinates on the fly? Can I create a 2D graphics engine that relies on a single square mesh to draw everything? It seems like a huge burden to be required to create a mesh for every little thing that may happen to pop up on the screen. It also seems strange that it''s so simple to set a different texture but not quite simple to modify U,Vs.

One other thing. Why is it that so many professional games have such horribly slow 2D interfaces? The games runs smoother than silk, then they throw up this horrid 2D interface where the mouse jumps 40 pixels per frame.. As a matter of fact, it seems like I can remember more games having slow interfaces than fast. Even the very most recent games.

Share this post


Link to post
Share on other sites
You could use a dynamic vertex buffer or simply use DrawPrimitiveUP methods to render directly from the system memory.
Unless you're calling DPUP tens to hundreds of times per frame, you may not notice the difference. For static geometry, though, video memory vertex buffers are the most efficient.

-Nik

EDIT: And, of course you can use vertex shaders to modify the existing coordinates on-the-fly - that way, you don't have to reupload the vertex data if only small changes are needed.
Then there is the concept of multi streaming, in where the texture coordinates are in a separate vertex buffer.
The above two are advanced techniques, but IMHO it is still beneficial for you to consider them at some point.

[edited by - Nik02 on May 8, 2004 4:49:03 PM]

Share this post


Link to post
Share on other sites

  • 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!