Jump to content
  • Advertisement
Sign in to follow this  

Pointer to Pointer

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

Hi, I have a pointer to a memory short* video = (unsigned short*)ddsd.lpSurface; to access the memory I have to do video [x + m_pitch * y] = color ========================================== Is it possible to use a double pointer to make it work like a two dimensional array short ** video to acess the memory video[x][y] = color; Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It's possible to do this with double pointers too.
Allocate an array of pointers to and use them as a lookup table for the video buffers' lines.
pixel **video;

void build_linebuf(pixel *surface, int pitch, int yres)
{
int y;
video = (pixel **) malloc(yres * sizeof(pixel *));

while(y = 0; y < yres; ++y) {
video[y] = surface;
surface += pitch;
}
)
However you'll have to access it as video[y][x] instead.

Share this post


Link to post
Share on other sites

unsigned short** map_2d_ushort_table(unsigned short* p, int pitch, int y_res)
{
unsigned short** tmp = new unsigned short*[y_res];

for(int y=0; y<y_res; ++y)
{
// pitch as number of pixels, not bytes
tmp[y] = p + y*pitch;
}
return tmp;
)

unsigned short** video = map_2d_ushort_table((unsigned short*)ddsd.lpSurface, m_pitch, y_res);

video[y][x] = color;


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!