Jump to content
  • Advertisement

Archived

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

reaptide

DDraw - Problem creating surfaces, and locking.

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

Hello everyone, I'm having some trouble with my DDraw program when it come to my surface creation function. I have the code listed below. The problem is that the surface does not seem to be created. I am unable to blit the surface or load and image into it. Can anyone figure out what is going on? The surface passed to the function is stored as a global. << START CODE >> // Create generic direct draw offscreen surface bool SSCreateSurface(LPDIRECTDRAWSURFACE lpDDS, int width, int height) { DDSURFACEDESC ddsd; HRESULT ddrval; ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight = height; ddsd.dwWidth = width; ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL); if (ddrval != DD_OK) { OutputDebugString("Couldn't create offscreen surface in SSCreateSurface() - DXUtils.cpp\n"); MessageBox(hWnd,"Couldn't create offscreen surface.","ERROR",MB_OK/MB_ICONSTOP); return NULL; } return TRUE; } << END CODE >> As well I was wondering whether it is necessary to lock a surface when blitting another surface to it, or if locking is only necessary when directly manipulating the surface pixels. Thanks for any help, Derek Edited by - Reaptide on 4/28/00 1:31:35 PM

Share this post


Link to post
Share on other sites
Advertisement
It is not necessary to Lock a surface when blitting ,think DD will do it for you automaticly.

Regarding the surfaceCreation question, your code seems ok,
the only thing I can think of is that ýou dont clear the DDSURFACEDESC structure. Try memset(&desc,0,sizeof(desc)) before loading it with data.

/ Tooon

Share this post


Link to post
Share on other sites
It is not necessary to Lock a surface when blitting ,think DD will do it for you automaticly.

Regarding the surfaceCreation question, your code seems ok,
the only thing I can think of is that ýou dont clear the DDSURFACEDESC structure. Try memset(&desc,0,sizeof(desc)) before loading it with data.

/ Tooon



Share this post


Link to post
Share on other sites
Maybe it has something to do with the pass by value on the Surface pointer. Try passing it by reference (with an ampersand), or passing in a pointer. Like:

bool SSCreateSurface(LPDIRECTDRAWSURFACE *lplpDDs, int width, int height);

Also, you should zero out your surface description with ZeroMemory or memset before using it.

Jesse Chounard

Share this post


Link to post
Share on other sites
Hello again,

It works now. I don''t have a clue why, but when I rewote the code to like it now does below it worked. If anyone feels like explain this to me, please feel free to do so.
WOOHOO!!

<< CODE START >>

LPDIRECTDRAWSURFACE SSCreateSurface(int width, int height)
{
DDSURFACEDESC ddsd;
LPDIRECTDRAWSURFACE lpDDS;
HRESULT ddrval;

ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwHeight = height;
ddsd.dwWidth = width;

ddrval = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
if (ddrval != DD_OK)
{
OutputDebugString("Couldn''t create offscreen surface in SSCreateSurface() - DXUtils.cpp\n");
MessageBox(NULL,"Couldn''t create offscreen surface.","ERROR",MB_OK/MB_ICONSTOP);
return FALSE;
}

return lpDDS;
}

lpDDSTest = SSCreateSurface(640, 480);

<< END CODE >>

Thanks for the help guys,

Reaptide

Share this post


Link to post
Share on other sites
It''s the ZeroMemory. You have to clear all the fields that you don''t want to fill out. So that''s why you have to call ZeroMemory. Just clear every structure before you pass it to DDraw.
Yoshi

The last truth is that there is no magic(Feist)

Share this post


Link to post
Share on other sites
It works because you are returning the surface. (The ZeroMemory is good too.) I believe it''s very similar to this situation:

void my_malloc(void *ptr, int size)
{
ptr=malloc(size);
}

This doesn''t work, but this does:

void* my_malloc(int size)
{
return malloc(size);
}

This has to do with passing by value vs passing by reference. The following code also works:

void my_malloc(void **ptr, int size)
{
*ptr=malloc(size);
}


Does that make sense?

Jesse Chounard

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!