Skip to main content
gamedev.net
🔒 Locked

Direct X tutorials...

Started by Zed Oct 21, 2000 at 5:03 PM 7 replies 550+ views
Original Post
Zed
Zed
Anyone know where to find very basic tutorials on DirectX kinda like setting up the window, using Ddraw... im using DirectX 7.0a SDK and MVC++ 6.0... i''d be glad to get some help.
Ironblayde
Ironblayde
I am writing a series on this... it starts with Windows programming in general, but you can always skip that if you know it already. Go to my site (link below) and check out the Resources section. Good luck.

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.
"Your superior intellect is no match for our puny weapons!"
Pouya
Pouya
the dx sdk has those too

...
Zed
Zed
Thank you Ironblayde! that''s some fat tutorials! i love ''em...
You have gotten a place in my favourites (consider it an onour
Thanks again. Its peapole like you who get the game community to work!
Ironblayde
Ironblayde
Zed: Wow, thanks!

AP: Blitting an offscreen surface is the same with a bitmap as without... could you be a little more specific as to exactly what you can do and what you need help with?

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.
"Your superior intellect is no match for our puny weapons!"
Fredric
Fredric
The AP was me... at school, once again.

Alrghty, well I''ve been having trouble loading a bitmap into an offscreen surface, and then being able to display it properly (in 16-bit).

I first setup the bitamp so it''s information is accesible, then I create the offscreen surface, next I lock the offscreen surface and finally, I use memcpy() to put the bitmap into the offscreen surface. But when I try to blt the offscreen surface to the backbuffer, which will then be flipped with the primary surface, it doesn''t work.

I don''t think my problem is blting the offscreen surface though, rather my problem might lay somewhere else like stuffing the bitmap into the offscreen surface (my offscreen surfaces using color keying). Could you maybe provide me with some working code in 16-bit that puts a bitmap into an offsceen surface and then blts it? Thanks!

twizz24@hotmail.com

If you place an infinite amount of monkeys in a room with an infinite amount of type-writers, they WILL type up the entire workings of Shakespeare
3D Math- The type of mathematics that'll put hair on your chest!
Ironblayde
Ironblayde
I just use the easy way for loading bitmaps; that is, using Windows API functions rather than writing my own loader. You just don't gain much by writing out 200+ lines of code to load a bitmap manually.

Here is what I use. This is very similar to what you would find it ddutil.cpp in the DirectX SDK.

                
BOOL ADXL_LoadBitmap(char *lpszFilename, HINSTANCE hInstance, int x, int y, LPDIRECTDRAWSURFACE7 lpdds)
{
HBITMAP hbitmap = NULL;
BITMAP bmp;
HDC image_dc, surface_dc;

// load bitmap resource

if (!(hbitmap = (HBITMAP)LoadImage(hInstance, lpszFilename,
IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION)))
{
// not a resource - load bitmap file

if (!(hbitmap = (HBITMAP)LoadImage(hInstance, lpszFilename,
IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION |
LR_LOADFROMFILE)))
{
return(FALSE);
}
}


// create device context for image

if (!(image_dc = CreateCompatibleDC(NULL)))
{
// release object

DeleteObject(hbitmap);

return(FALSE);
}


// select bitmap into the DC

if (!(SelectObject(image_dc, hbitmap)))
{
// release objects

DeleteDC(image_dc);
DeleteObject(hbitmap);

return(FALSE);
}


// get surface device context

if (FAILED(lpdds->GetDC(&surface_dc)))
{
// release objects

DeleteDC(image_dc);
DeleteObject(hbitmap);

return(FALSE);
}


// get image dimensions

GetObject(hbitmap, sizeof(BITMAP), &bmp);

int dx = bmp.bmWidth;
int dy = bmp.bmHeight;


// copy image to surface

if (!(BitBlt(surface_dc, x, y, dx, dy, image_dc, 0, 0, SRCCOPY)))
{
// release objects

lpdds->ReleaseDC(surface_dc);
DeleteDC(image_dc);
DeleteObject(hbitmap);

return(FALSE);
}


// get rid of all that stuff we used

lpdds->ReleaseDC(surface_dc);
DeleteDC(image_dc);
DeleteObject(hbitmap);


// success!

return(TRUE);
}


That's kinda long, but it's mostly just the same 2-3 lines over and over to release everything, heh. There are better ways to do it but that's what I have right now.

This is almost identical to the load function that is used for GDI-based programs, and so I've covered every part of this function in detail in my GDI tutorial on my website. Once you've created two surfaces, lpddsPrimary and lpddsOffscreen, you could load a bitmap and blit the image like this:

if (ADXL_LoadBitmap("text.bmp", NULL, 0, 0, lpddsOffscreen))
    lpddsPrimary->Blt(NULL, lpddsOffscreen, NULL, DDBLT_WAIT, NULL);

This is all the same for any color depth, as the WinAPI functions will automatically convert the color data to work with whatever display mode you happen to be using. Hope this helps...

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.


Edited by - Ironblayde on October 24, 2000 2:25:18 PM
"Your superior intellect is no match for our puny weapons!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.