Jump to content
  • Advertisement
Sign in to follow this  
azjerei

glTexCoord2f

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

How do I use glTexCoord2f to draw only a small portion of a texture??? I have tried (u/texture_width, v/texture_height) as the arguments, where x and y are the desired coordinates. For example, if I want to draw only half of a 256x256 texture, I would define the glTexCoord2f calls like this: // top-left glTexCoord2f(0/256, 0/256); // top-right glTexCoord2f(128/256, 0/256); // bottom-right glTexCoord2f(128/256, 128/256); // bottom left glTexCoord2f(0/256, 128/256); Is this correct? It does not work at all.... :(

Share this post


Link to post
Share on other sites
Advertisement
due to integer "rounding", I think you need to explicity convert to floating point.


// top-left
glTexCoord2f(0.0f/256.0f, 0.0f/256.0f);

// top-right
glTexCoord2f(128.0f/256.0f, 0.0f/256.0f);

// bottom-right
glTexCoord2f(128.0f/256.0f, 128.0f/256.0f);

// bottom left
glTexCoord2f(0.0f/256.0f, 128.0f/256.0f);

Share this post


Link to post
Share on other sites
glTexCoordf takes floating point values.



128/256 is 0. Because 128 and 256 are both integers C does integer arithmetic on them. Try 128.0f/256.0f.



Since texture coords go from 0 to 1, you might find it better to think in terms of 'I want half the texture, that's 0.0, 0.0 to 0.5, 0.5' rather than worry about how wide your texture is in pixels and how any a given proportion of them is.



dave j

Share this post


Link to post
Share on other sites
Quote:
Original post by azjerei
No, that's not it.


What you mean to say is "Thank you for taking the time to read and answer my post. Your help is appreciated, however I am still experiencing a problem, which I shall thoroughly explain..."

Share this post


Link to post
Share on other sites
What they said above is correct. When you divide two integers all decimal places are dropped, not rounded, so all your divides would give you 0 in this instance.

Please be more polite in future.

Share this post


Link to post
Share on other sites
I know that already, and that is not the cause since I am already using float values, not that it does really matter in thise case since they are typecasted anyhow.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by azjerei
I know that already, and that is not the cause since I am already using float values, not that it does really matter in thise case since they are typecasted anyhow.


Are you actually trying to solve your problem ? or are you trying to promote a discussion about how incompetent you are at looking for help ?

Simply put, from your original post above, given the information you posted, the only discernable problem is the fact that you're using ints instead of floats. Using floats or using 0.0f and 0.5f instead of your more clumsy 0/256 128/256 provides a solution to that problem. if you are STILL having problems, the problem is somewhere else in your code, so try and work out where and post it. And be more appreciative.

Daire Quinlan.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by azjerei
I know that already, and that is not the cause since I am already using float values, not that it does really matter in thise case since they are typecasted anyhow.


Are you actually trying to solve your problem ? or are you trying to promote a discussion about how incompetent you are at looking for help ?

Simply put, from your original post above, given the information you posted, the only discernable problem is the fact that you're using ints instead of floats. Using floats or using 0.0f and 0.5f instead of your more clumsy 0/256 128/256 provides a solution to that problem. if you are STILL having problems, the problem is somewhere else in your code, so try and work out where and post it. And be more appreciative.

Daire Quinlan.


Ditto! =)

Share this post


Link to post
Share on other sites

This topic is 4912 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.

Guest
This topic is now closed to further replies.
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!