Advertisement

SetPixel DDraw function

Started by February 13, 2000 09:24 PM
3 comments, last by Gecko 24 years, 7 months ago
i''m trying to implement a SetPixel function (should be easy, huh?) but i can''t get the frigging thing to work! it only draws half the pixels i tell it to. void SetPixel(LPDIRECTDRAWSURFACE4 surf, int x, int y, DWORD color) { DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); if(FAILED(surf->GetSurfaceDesc(&ddsd))) { GameError("SetPixel: Couldn''t get surface desc"); return; } if(FAILED(surf->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL))) { GameError("SetPixel: Couldn''t Lock the surface"); return; } int pos = y*ddsd.lPitch+x; BYTE *dest = (BYTE *)ddsd.lpSurface; dest[pos] = color; // BYTE *dest = (BYTE *)ddsd.lpSurface; // dest += ddsd.lPitch*y; // dest[x] = color; if(FAILED(surf->Unlock(NULL))) { GameError("SetPixel: Couldn''t Unlock the surface"); return; } } in my game loop, i have this: for(int x=0; x<1024; x++) SetPixel(BackBuff, x, 0, GetRGB(255,255,255)); my app is 1024x768, btw. the problem is it only draws halfway across the screen rather than drawing a white line all the way across the first row of pixels. sorry about the long post. Thanks
_________________Gecko___

_________________Gecko___Gecko Design
Did you try using other pointer types for the dest variable? I think it may have to be WORD * or DWORD * instead of BYTE *.
Advertisement
oh my god, i can''t beleive i did that. of course it doesn''t work, my surface is in 16 bit (DWORD) and i tried filling it with 8 bit (BYTE). thanks for pointing that out!


_________________Gecko___

_________________Gecko___Gecko Design
you will probably need to declare your pointer at WORD, but you will need to divide your pitch by 2, because it is given in number of bytes and you need the number of words

cyberg
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft
aaaaaahhhhhhhh... i saved thousands and thousands of dollars by switching to Gieko!
Carl "trixter"[email=carl@trixoft.com]carl@trixoft.com[/email]http://www.trixoft.com

This topic is closed to new replies.

Advertisement