# glTexCoord2f

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
due to integer "rounding", I think you need to explicity convert to floating point.

// top-leftglTexCoord2f(0.0f/256.0f, 0.0f/256.0f);// top-rightglTexCoord2f(128.0f/256.0f, 0.0f/256.0f);// bottom-rightglTexCoord2f(128.0f/256.0f, 128.0f/256.0f);// bottom leftglTexCoord2f(0.0f/256.0f, 128.0f/256.0f);

##### 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 on other sites
No, that's not it.

##### Share on other sites
Quote:
 Original post by azjereiNo, 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 on other sites
Heh.. if you say so.

##### 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 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 on other sites
Quote:
 Original post by azjereiI 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 on other sites
Quote:
Original post by Anonymous Poster
Quote:
 Original post by azjereiI 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 on other sites

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009805
• ### Who's Online (See full list)

There are no registered users currently online

×