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

Drawing a single pixel to screen with lock

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

Could anyone tell me how is drawing to screen done exactly (direct x) I have tried to do it but I only get lot of errors and blue screens. This is the way I have tried. Please help =? #include "lock.h" //class DrawToSurface //first I have locked the surface... BOOL DrawToSurface::Lock() { if(lpSurf==NULL) return FALSE; lpSurf->Lock(NULL,&ddsd,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR,NULL); Locked=TRUE; return TRUE; } //then I have used this function to draw pixel... void DrawToSurface::DrawPixel(unsigned int x,unsigned int y,short color)//have to use 16 bit color mode { if(!Locked) return; if(x>ddsd.dwWidth||y>ddsd.dwHeight) //check if the coordinates are OK return; short *ptr =reinterpret_cast(ddsd.lpSurface ); ptr=ptr+(x+(y*ddsd.lPitch)); *ptr=color; } //and UnLocked the surface... void DrawToSurface::UnLock() { if(lpSurf==NULL) return; Locked=FALSE; lpSurf->Unlock(NULL); }

Share this post

Link to post
Share on other sites
First of all, in your Lock() function, you never clear ddsd, that''s bad
Add this right before lpSurf->Lock():
ddsd.dwSize = sizeof(ddsd);

Try this to draw your pixel (16bit):

USHORT *surface;
surface = (USHORT*)ddsd.lpSurface;
surface[x + y*lpitch] = color;

Have to go now, bye!

- Goblineye Entertainment
The road to success is always under construction

Share this post

Link to post
Share on other sites