Jump to content
  • Advertisement

Archived

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

Jonppe

Drawing a single pixel to screen with lock

This topic is 6497 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
Advertisement
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
There is a tutorial all about using Lock and writing to DDraw Surfaces Directly at www.mr-gamemaker.com

Hope it helps

Share this post


Link to post
Share on other sites
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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!