Archived

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

Jonppe

Drawing a single pixel to screen with lock

Recommended Posts

Jonppe    122
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
Tornado    122
First of all, in your Lock() function, you never clear ddsd, that''s bad
Add this right before lpSurf->Lock():
memset(&ddsd,0,sizeof(ddsd));
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
furby100    102
I cast my ddsd.lpSurface like this:
ptr = (USHORT*)ddsd.lpSurface;
I also use a USHORT * rather than a short *. This is because shorts have a sign bit and therefore intefere with 565 16-bit.

------------------------------
#pragma twice


sharewaregames.20m.com

Share this post


Link to post
Share on other sites