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


reading pixels...

Recommended Posts

hi, I have two question: 1. how do I read the color values of a single pixel from a texture under Directx8? I''m ussing textured reqtangles which I store in vertexbuffers to make a simple 2d game now for my pixel perfect collision detection I need to know how to read a single pixel from a surface....? or is there maybe a better way to do this? 2. are vertex buffers the best way to store 2 traingles that form a square? or is the a better way and if so...what would that be? any help would be appreciated...thanks Chris

Share this post

Link to post
Share on other sites
1) See below, this is what I do to read a single pixel from a texture. The texture I have is created D3DPOOL_SCRATCH... SCRATCH leaves the file format in CPU memory and I believe it makes its a standard format... So it always ends up being 32 bit even if its a 8 bit greyscale bmp... So my algorithm assumes its 32 bit. (y and x are the location on the BMP)


p_Tex->LockRect(0, &info, 0, D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);

char *pointer;

pointer = (char *)info.pBits;
pointer += (info.Pitch * y);
pointer += (4 * x);

col.b = *pointer;
col.g = *(pointer + 1);
col.r = *(pointer + 2);
col.a = *(pointer + 3);


2) Yes... Have everything in VertexBuffer.

Share this post

Link to post
Share on other sites