create surface

Started by
6 comments, last by djsteffey 23 years, 4 months ago
  
//mainDD is the DirectDraw4 object

// surface is a LPDIRECTDRAWSURFACE4 surface

// w and h are variable width and height


    DDSURFACEDESC2 ddsd;
    ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = w;
    ddsd.dwHeight = h;
    if (mainDD->CreateSurface(&ddsd, &surface, NULL) != DD_OK)
		return false;
	return true;
  
what is wrong with this. It returns true (this is in a function) that the surface was created. But then I go to lock the surface and draw pixels to the surface, that doesnt give me any errors. Then i go to draw the surface and that doesnt give me any errors.......but nothing is ever showed on the screen !!! I draw to the backbuffer then i flip the backbuffer and the primary surface to show it on screen. I know the pixel drawing routines work b/c i tried them on the backsurface directly and they work fine. It just doesnt work when i create a surface like this. Any help is appreciated "Now go away or I shall taunt you a second time" - Monty Python and the Holy Grail themGames Productions
Advertisement
Maybe your surface must have the same format as the back surface.
Hope this help
ChMar
ChMar
It seems that you are not creating a back-buffer (I assume that''s what you want) but actually an off-screen plain.

ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

This is simply a surface that''s not meant for displaying.
The only way to display such a surface would be copying its contents (blitting) to the front or preferrably back buffer.

The fact that you can draw pixels to the surface is normal; remember, off-screen surfaces are for manipulating and preparing display and after that you copy them to one of your (back)buffers.

You should create a back-buffer by simply setting the appropriate flag when you create your main surface; see the SDK.

Good luck!

(Whoops sorry... doubleposted. The above anonymous answer was mine.)

Edited by - Sven Vermeulen on November 30, 2000 7:03:10 AM
i am not trying to create the backbuffer. I have already done this. What i am trying to do is create a surface of a specified size and then load the image from my own custom image file format. My file format contains the width, height, pixel data and various other pieces of info. So i want to create the blank surface according to the w and h and then load my data onto the imgae. I know the loading is correct, b/c i can load it directly to the back buffer and flip and see it. That is why i know the loading works.
chMar---what do you mean by same format ? Same pixel format or seomthing. Doesnt the directDraw object take care of that when you create the surface. Or what do you mean ?


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

OK, misunderstood you...
So say you''ve written al your pixels to the off-screen plain, what else do you do in order to actually display it on-screen ??
i then treat it the same way that i do a surface that was created out of a bmp. I use the DDutil file to create a surface from a bmp file. All that works fin and it gets displayed fine and I have been using it for a while now. So after i create the blank surface and put my pixels on it, try to display it using the same functions that display my surfaces created out of bmps from the DDUtil file.......it just doesnt show up. Could it be something with the color keying ? I always clear my screen to 0, 0, 0 when i clear the back buffer. Could it be that the color keying on my new surface is messed up where any 0, 0, 0 pixels gets written over it ?

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

To avoid color-keying problems, use the DDBLTFAST_NOCOLORKEY flag (or DDBLT_NOCOLORKEY) when you blit to the backsurface.

This topic is closed to new replies.

Advertisement