Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

As explained in the SDK it is possible to draw bit by bit into a surface.

Still orientating on Directx, I'm trying to do so.

 

Short summary on my intents:

 

*Make a surface using CreateOffscreenPlainSurface

*Lock this surface

*Modify the bytes using pointer given by LockRect

*Unlock the surface

*Copying this surface into the backbuffer using UpdateSurface

 

Some things I'm aware of:

 

*It's perhaps also possible to acces the backbuffer directly, but one step at a time for me.

*I need to lear a lot about DirectX, that's why I'm here, hoping to learn from you :-)

*currently as a start I'm only making and copying a grey surface, when that succeeds I'll be plotting individual pixels.

 

My question:

 

*When I run my program, I get no errors but the screen remains black, in stead of greyish, what I think, or would like it to be.

Can someone help me out figuring what I did wrong?

 

 

Globals:

 

LPDIRECT3D9         g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9   g_pd3dDevice = NULL; // Our rendering device

LPDIRECT3DSURFACE9 	g_p2DSurface; // the pixelplotting surface

int g_width; // is assigned the value of d3dpp.BackBufferWidth resp. Height
int g_height;

 

CreateOffscreenPlainSurface (done in InitD3D)

 

g_pd3dDevice->CreateOffscreenPlainSurface(	d3dpp.BackBufferWidth,
											d3dpp.BackBufferHeight,
											d3dpp.BackBufferFormat,
											D3DPOOL_DEFAULT,
											&g_p2DSurface,
											NULL);

 

 

 

 

My adaptation of Render() and were I think all essential information/error should be.

 

VOID Render()
{
   if( NULL == g_pd3dDevice )
       return;

   // Clear the backbuffer to a blue color

   g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0 ), 1.0f, 0 );

   // Begin the scene
   if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
   {
   
// Rendering of scene objects can happen here

//Creating a rectangle which is to be locked	
D3DLOCKED_RECT rectLock = {0};

//Locking the drawing surface
g_p2DSurface->LockRect(&rectLock,NULL,D3DLOCK_DONOTWAIT | D3DLOCK_NOSYSLOCK );

//The place where pixels are to be altered, byte by byte.
BYTE* pBits;
//Adressing the surface bytebuffer
pBits = (BYTE*)rectLock.pBits;

//Looping through all the pixels in the surface
for (DWORD y=0;y<g_height;++y)
{
for (DWORD x=0;x<g_width;++x)
{
DWORD index= (x*4)+(y*rectLock.Pitch/4);
pBits[index]   = (BYTE)128;// Blue
pBits[index+1] = (BYTE)128;// Green
pBits[index+2] = (BYTE)128;// Red
pBits[index+3] = (BYTE)128;// Alpha
}
}

g_p2DSurface->UnlockRect();

IDirect3DSurface9* pBackbuffer;

g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pBackbuffer);

g_pd3dDevice->UpdateSurface(g_p2DSurface,NULL,pBackbuffer,NULL);


       // End the scene
       g_pd3dDevice->EndScene();
   }

   // Present the backbuffer contents to the display
   g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

Edited by rouke
Posted

nevermind :-)

 

Found out that StretchRect instead of UpdateSurface does the job!

 

@moderator: This thread can be deleted, thanks anyways, sorry for the mess ;-)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...