• Advertisement
Sign in to follow this  

glTexCoord2f

This topic is 4735 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
*sigh*

Every time I come here, people start doing this!!! RIGHT, YOU WIN YOU FUCKING BASTARDS :P

Ban me, I won't return to this shit site that cannot help anybody with anything consistent.

A big F.U.C.K. Y.O.U. to everybody :)

Share this post


Link to post
Share on other sites
lets see;
- you gave us no real infomation to help you
- based on that little infomation someone tried to help
- you responded in a rude way and provided no more infomation

in short : you wont be missed.

Share this post


Link to post
Share on other sites
heh, suddenly I am on an MMO forum....wierd

*looks for nearby transdimensional portal

anyway, they answered your question, you eidther didn't understand them or didn't actually try and change things and then got hostile when they complained about your rudeness. good-times.

to be more clear, you'll note the .0f they put after all the numbers in your function call. did you actually try adding those? I promise it will change your results.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
lets see;
- you gave us no real infomation to help you
- based on that little infomation someone tried to help
- you responded in a rude way and provided no more infomation

in short : you wont be missed.

LOL :)

Share this post


Link to post
Share on other sites
if you don't believe the guys try this small program and see the result

#include <iostream.h>
void main(){
cout<<128/256;
}

Share this post


Link to post
Share on other sites

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