Sign in to follow this  
h3ro

How to store a texture?

Recommended Posts

Hey, I am not sure if this question belongs here or general programming, but here it goes. Im using a API which when loading a texture return a BYTE pointer containing all the pixel info. I just want to know if there is any reasons for storing it as a pointer? Right now trying to implement rotation and then new a x,y value for each pixel. So when I load a texture now I convert it from the BYTE pointer into an array of pixels(xPos,yPos and color info) So my question is; Is there a really good reason to originally save it as a BYTE pointer or is it ok to converter it? Hope my question makes some sense at least. Thanks in advance

Share this post


Link to post
Share on other sites
There's no difference between a BYTE pointer and a BYTE array. Both are blocks of memory containing data. You can iterate over the BYTE pointer like you could an array. If you want to create an object to automate that stuff for you, that makes sense.


class Texture
{
BYTE *mData;
unsigned int mWidth;
unsigned int mHeight;

public:
BYTE *getPixel( unsigned int w, unsigned int h )
{
assert( w < mWidth && h < mHeight );
return &mData[ w + h*mWidth ];
}

//etc
};



[EDIT: i get what you're saying now. sure that sounds fine, but again i think you could just abstract it a little and then not need to change the underlying storage format (i.e. still use an array of BYTE and just have a Pixel class that takes a BYTE* and converts it to your pixel format). That way you don't need to be copying around all the data and then re-exporting it to a BYTE* to actually use it]

-me

Share this post


Link to post
Share on other sites
Thanks for your reply.

I now use a pixel struct like this

struct pixel
{
float xPos, yPos;
BYTE r,g,b,a;
};



And store that in a std::vector. So im not converting data back and fourth and the time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this