iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme .NET Talk > .NET > Graphics and Multimedia > DirectX > How to create big surfaces?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2003, 09:21 PM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Angry How to create big surfaces?

I want to use a big map in my little game, but the srolling is rather slow.
How to create a surface whose width and height are larger than the display device?
Reply With Quote
  #2  
Old 08-21-2003, 01:37 AM
Nerseus's Avatar
Nerseus Nerseus is offline
Danner

Preferred language:
C#
 
Join Date: Oct 2002
Location: Arizona, USA
Posts: 2,546
Default

In general, you don't want to do that. A surface is essentially a texture which has limits on most cards (256x256 is not uncommon, though you might find 2048x2048 on *some* cards). If you're talking about 2D or 3D with a background, you'll need to piece together multiple surfaces, usually. DirectDraw has some built-in methods, if I remember correctly, for handling large surfaces more easily thand Direct3D. But if you're talking about a game map that's bigger than the screen, you'll need some kind of tile-based layout (the most common).

-Nerseus
__________________
"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Reply With Quote
  #3  
Old 08-21-2003, 02:43 AM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Default

Thanks for your explanation, currently my code like this:
//------------------------------------------------------------------------
public void DrawTile(int x,int y,Tile pic)
{
int w=pic.Width;
int h=pic.Height;
Bitmap bm=pic.ImageData;
bool cut=false;
if(pic.Width>ScreenWidth-x)
{
w=ScreenWidth-x;
cut=true;
}
if(pic.Height>ScreenHeight-y)
{
h=ScreenHeight-y;
cut=true;
}
if(cut)
{
Rectangle srcRect=new Rectangle(0,0,w,h);
bm=pic.ImageData.Clone(srcRect,pic.ImageData.PixelFormat);//GDI+ Function
}
description.Clear();
description.SurfaceCaps.OffScreenPlain=true;
Surface surface=new Surface(bm,description,display);
back.DrawFast(x,y,surface,DrawFastFlags.Wait);

surface.Dispose();
}
//---------------------------------------------------------------------------
The mixed use of DirectDraw and GDI+ make the draw speed
very slow.
How to solve this problem?
Is there a similar problem in Direct3D?

Last edited by Liu Junfeng : 08-21-2003 at 02:56 AM.
Reply With Quote
  #4  
Old 08-21-2003, 02:56 AM
wyrd's Avatar
wyrd wyrd is offline
Senior Contributor

Preferred language:
C#
 
Join Date: Aug 2002
Location: California
Posts: 1,408
Default

Well, one thing you want to avoid is cloning an image and creating a new surface everytime you draw a tile. Create an array of surface tiles (lookup table) that's created when the class is instantiated, then you can just snag the already built surfaces without having to go through the pain of creating them each time you draw.
__________________
Gamer extraordinaire. Programmer wannabe.
Reply With Quote
  #5  
Old 08-21-2003, 03:04 AM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Default

But the x and y position are not foreseeable;
if I use 8 pixels as the step of x and y, then
how many surfaces should I create ?
Reply With Quote
  #6  
Old 08-21-2003, 06:10 AM
AndreRyan AndreRyan is offline
Junior Contributor

Preferred language:
VB.Net
 
Join Date: Jan 2002
Posts: 366
Default

You should create a Surface, not a Bitmap. Put the surface in an array an use:
Code:
public void DrawTile(int x, int y, int SurfNum)
{
    back.DrawFast(x,y,SurfaceArr(SurfNum),DrawFastFlags.Wait);
}
Just load the pictures in to surfaces at the start of the program and then Blt the surfaces instead of creating it each time.
__________________
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Reply With Quote
  #7  
Old 08-21-2003, 08:54 AM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Default

I tried so, the image file is 1024*768;divided into 16*16 cells
and create surfaces of 640*480, then more than 100M memory
is used; if use 8*8 cell, outofmemory exception occured.

SO, for a scrolling game, you can't create surfaces for each frame at the same time.

If I create surfaces of size 16*16, the memory is ok, but the drawing speed is even slower.
Reply With Quote
  #8  
Old 08-21-2003, 12:15 PM
wyrd's Avatar
wyrd wyrd is offline
Senior Contributor

Preferred language:
C#
 
Join Date: Aug 2002
Location: California
Posts: 1,408
Default

Ah, yeah memory usage. Forgot about that.

Instead of holding surfaces in the array, just hold Rectangle structures that describe the image itself, so you can draw it directly off your tile bitmap and not have to create any extra surfaces.

You may also want to take a look at my Map class in my Sharp Invader game. What I did was create a two-dimensional array, which basically was my map. The two-dim array was made up of objects, each describing a tile on the map. They didn't hold surfaces or bitmaps, just info that you could draw based off of. That way you have no extra surface, but just 1 single image of your tiles.

There are also several tutorials on GameDev.net about how to make tile and isometric map engines. You may find them useful. http://www.gamedev.net/reference/list.asp?categoryid=44
__________________
Gamer extraordinaire. Programmer wannabe.
Reply With Quote
  #9  
Old 08-22-2003, 01:55 AM
shouzama shouzama is offline
Freshman

Preferred language:
VB.NET
 
Join Date: Jan 2003
Location: Another World
Posts: 38
Thumbs up

Thanks wyrd, very good link!
Reply With Quote
  #10  
Old 08-22-2003, 02:33 AM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Default

But there isn't a function such as
Code:
public void Draw(
    Rectangle destRectangle,
    Bitmap source,
    Rectangle srcRectangle,
    DrawFlags flags
);
There only exists:
Code:
public void Draw(
    Rectangle destRectangle,
    Surface sourceSurface,
    Rectangle srcRectangle,
    DrawFlags flags
);
After reading "Using Direct3D For 2D Tile Rendering ", I think I should learn Direct3D first.
Reply With Quote
  #11  
Old 08-22-2003, 02:49 AM
wyrd's Avatar
wyrd wyrd is offline
Senior Contributor

Preferred language:
C#
 
Join Date: Aug 2002
Location: California
Posts: 1,408
Default

Well, even so the logic of a tile based map engine is the same (so your map isn't drawn so slowly.. which was one of the problems you were having I believe). You'll just need to convert the Bitmap into a Surface. For that I can't help you. I don't know DirectX. Hopefully someone else will pop in and help you out with that.

Also.. have you considered learning DirectDraw instead of Direct3D? If you're doing a simple game then Direct3D would be overkill and is much harder to learn IMO.
__________________
Gamer extraordinaire. Programmer wannabe.
Reply With Quote
  #12  
Old 09-28-2003, 07:53 AM
Liu Junfeng Liu Junfeng is offline
Newcomer

Preferred language:
C#
 
Join Date: Aug 2003
Posts: 12
Default

I recreated wyrd's SharpInvader game with Managed Directdraw;
you can download it from:
http://www.funnyok.net/rufi/ware/Invader.rar
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Surfaces Vs. Textures please help LDV DirectX 2 04-12-2004 07:52 PM
Locking DirectDraw Surfaces Loki DirectX 9 03-21-2004 01:07 PM
need help with StretchRectangle and Surfaces TripleT DirectX 0 10-20-2003 11:54 AM
Error when trying to restore surfaces. wyrd DirectX 8 10-18-2003 01:32 PM
Surfaces? mutant Graphics and Multimedia 6 05-12-2003 01:24 PM

Advertisement: