Drawing a single pixel to screen with lock
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);
}
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
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
There is a tutorial all about using Lock and writing to DDraw Surfaces Directly at www.mr-gamemaker.com
Hope it helps
Hope it helps
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement