Archived

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

glTexCoordPointer without floats?

This topic is 6032 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 notice you can use GL_UNSIGNED_SHORT instead of GL_FLOAT in glTexCoordPointer. Does this mean that if I know my texture width and height ahead of time, rather than putting in 0.5, 0.5, for UV coordinates, I can instead put the actual pixel offset like 256, 256 for a 512*512 texture? This would save a lot of room considering a float is 4 bytes, and I could get away with 2 bytes each (or even 1 byte each if the texture width and height was 256 pixels.) I tried it and it didn''t seem to work. I was just wondering if it was something I did, or if it is not possible. Ultimately, I would love to have a single array of texture vertices, and be able to index them with an array like you can with regular vertices.

Share this post


Link to post
Share on other sites
I can''t really answer your question, but I''m curious as to why you want to use unsigned shorts instead of floats. You said to save space, but do you mean in the file or when it''s loaded? If it''s in the file there are ways of shrinking down the size of floats if they''re between 0.0 and 1.0, you don''t need to use a short for that. If it''s in the program it makes sense, but I don''t think it''s worth the potential speed loss of using a 16 bit variable on a 32 bit system. Just my two cents on the whole thing.

Share this post


Link to post
Share on other sites
using 16 bit variables on 32 bit systems would have little impact, if any, on performance, other than a speed boost.

I haven''t been able to correctly use non-floats for texture coords. So unfortunatly, you seem to be out of luck.

But, using low-byte data types can be a huge advantage to speed, because if you program correctly, the biggest limit to performance will be bus speed, and its bandwidth, so halving the number of required bytes will significantly boost your potential performance. But, there are exceptions, for example, I''ve found using shorts with VAR can be quite slow. Also, your should ALWAYS use bytes for colour data. Not only is there 4 times LESS data to transfer, colours are displayed as bytes, (0-255), so it''s impossible to drop precision.

Share this post


Link to post
Share on other sites
A short will not work at all if you want to use a value like .5.
The compiler will either round it up or down depending the compiler. If you want to use a decimal value you need to have a float or a double.

Share this post


Link to post
Share on other sites
I am doing it to simply save space in my object files. I am using non repeating textures for my models, so I was thinking I could greatly reduce the size of my object files if I could go from a float (4 bytes) down to a short (2 bytes), or even 1 byte, for each U and V coordinate

I mean, if you had a texture that was 256*256, and you could have bytes for UV like:

0, 64
13, 28
128, 256
.
.
.

That would be awesome.

You must be able to use the lower sizes because they are allowed in the glTextCoordPointer function. All I need to know is what IS the short. What IS the byte? Are they smaller versions of floats, or pure decimal numbers?

Share this post


Link to post
Share on other sites
Both shorts and bytes are integers. byte''s and char''s are the same.
shorts range: -32k to 32k.
unsigned short range: 0 to 64k
byte range: -128 to 127
unsigned byte range: 0 to 255

You can always just use a conversion when loading the data.

Share this post


Link to post
Share on other sites
Just remember that as long as you keep the numbers whole number values you should be able to use shorts. But if you have a decimal value cordnate like .5 it will be saved as a 0 because it will drop the decimal points right off the end of it.

Darin Perkins
Game Design Student
Full Sail, Orlando, FL
E-Mail: BigMeph@netzero.net
Home Page: home.earthlink.net/~bigmeph

Share this post


Link to post
Share on other sites