Mein Mein wrote:
Isn’t there a nicer way to do this?? some kind of clipping in the texture
or something… somthing that doesn’t slow my program down ofcourse 
Division is always slow on computers. They can add and multiply all you
could possibly want – but subtraction and division are gonna be slow.
Try pre-setting the amount you want:
Most (all?) C compilers in use today are going to do the 54.f/64.f calculation
at compile time and hard-code the result into the two orginal glTexCoord2f
calls.
In fact, the following code is going to hurt performance more than the
original, because it requires assembly instructions to push the float
shownSize onto the stack. If, however, you were to throw a “const” in there,
the result should be the same as the original code.
The only way I can think of to make this more efficient, is to change the
first and last glTexCoord2f calls that use only 0 or 1 into glTexCoord2s(),
but the speed difference there is negligible, unless you’re using this code
fairly often, or if you need the time to do alot of other things.
float shownSize = 54f / 64f;
…
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(x, y);
glTexCoord2f(shownSize, 0); glVertex2i(x+w, y);
glTexCoord2f(shownSize, 1); glVertex2i(x+w, y+h);
glTexCoord2f(0, 1); glVertex2i(x, y+h);
glEnd();
Goes back to the old days of programming when answers to hard
mathematical computations were stored in lookup tables rather than
calculated on the fly. (Okay, not exactly the same thing.) It’s a
great tool to use! I mean, REALLY great!
Lookup tables are used in cases where it will be more efficient (in preportion
to the loss in precision) to compute an integer offset, and load from that
offset, than to compute a precise result.On Wednesday 17 November 2004 03:16 pm, Scott Harper wrote:
–Scott
PS: In looking back, I realize that you didn’t mention having slowdowns
already… But still this technique can help make things easier to look
at and immediately understand what’s going on in the code.
Also, why not make a texture struct (or object or something – I use
Java, so I’m not familiar with what’s best in C++) and inside you can
store the texture id, and the left, top, right, and bottom sides of your
texture in floats. This would help for a tile-based solution where you
load ONE texture which is broken into smaller parts.
Anyway, my $.02.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl