Thread: DirectX

  1. #1
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469

    Arrow DirectX

    Does anyone know of an free online DirectDraw tutorial(preferably DirectX 8.1 for VC++ .NET)?

    [EDIT]
    This thread is now for anyone who has questions about DirectX
    [/EDIT]
    Last edited by Driveway; 05-21-2002 at 02:18 PM.

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    The SDK docs.
    or
    www.drunkenhyena.com
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  3. #3
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Thanks, I looked at the SDK, they're not that good. Anyways, I was looking for a DirectDraw, not 3D tutorial. Sorry I forgot to mention.

  4. #4
    try Sunlight's DirectX tutorial. I think it is pretty good
    He also has a DirectX tutorial for .net

  5. #5
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Thanks. Please keep posting more tutorials people!!
    Last edited by Driveway; 05-18-2002 at 01:53 PM.

  6. #6
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469

    Angry

    I tried your first link and, it didn't work. I also found out your second link was for intermediate and advanced C++ .NET, I just got it. Oh well. Plus, it didn't have exactly what I was looking for.

  7. #7
    It didn't work?

    try his home page and follow the link on your left.
    http://sunlightd.virtualave.net/default2.htm

    or here is an other tutorial
    http://nexe.gamedev.net/Tutorials/List.asp
    this is from the creators of the Nehe tutorial for OpenGL. Haven't read this one but I think it is pretty good (there OpenGL tutorial was good I've heard)

  8. #8
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    I don't mean the link didn't work, I mean the code didn't work. Thanks for the new link. I'll tell you if it doesn't *work*

  9. #9
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Dope! I was looking for 2D, that's all 3D stuff. Ahhh, I can't find anything. I even bought a book about a week ago, but the code in there doesn't work either! DOPE. Is there something wrong with my compiler? I have made things before. The only DirectX code that works is the one that comes with the SDK, and that doesn't have a blank screen I could work off of. Could someone write a program that displays a blank fullscreen and exits when you hit escape (and make sure it works in VC++ .NET )? PLEASE? Thanks in advance. Or you could just post another tutorial that hopefully works. And rember DirectX 8.1
    Last edited by Driveway; 05-19-2002 at 11:44 AM.

  10. #10
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    You really should just use DirectGraphics and ignore the 3D parts of it. That would be easiest. But if you really want to use DirectDraw then check out "Inside DirectX" or "Windows Game Programming For Dummies". I have both and I think you'll find more of what you're looking for.

    or try here and browse though the graphics and multimedia section.
    http://msdn.microsoft.com/archive/default.asp
    Last edited by taylorguitarman; 05-19-2002 at 12:28 PM.

  11. #11
    Unregistered
    Guest
    While you were writing that, I was doing some work of my own. I got rid of the linking errors I had before even though there shouldn't have been because it was linked, and now I only have one error. Here is the error:

    c:\C++\DirectX\main2.cpp(91): error C2664: 'CreatePalette' : cannot convert parameter 1 from 'LPDIRECTDRAWSURFACE' to 'const LOGPALETTE *'

    And here is the line of code:

    lpPrimaryPalette=CreatePalette(lpPrimary);

    And here are the defining thingies for the stuff:

    extern LPDIRECTDRAW lpDirectDrawObject;
    extern LPDIRECTDRAWSURFACE lpPrimary;
    //I'm pretty sure it's this one causing the trouble
    extern LPDIRECTDRAWPALETTE lpPrimaryPalette;

    Could someone tell me how to fix that?

    P.S. - If the extern things aren't supposed to be like that, don't blame me, blame the author of my book.

  12. #12
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Sorry, that was me, I wasn't logged in.

  13. #13
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121
    >>DirectDraw tutorial(preferably DirectX 8.1 for VC++ .NET)?

    DirectDraw became obsolete in DX7 and is no longer being updated, so if you're intent on learning DirectDraw a DX7 tutorial would be just as good as DX8.1, if you just want 2d but dont specifically need DirectDraw then the new DirectGraphics component would be better to learn in the long run, as it translates easily into 3d as well as being the new DirectDraw replacement.

  14. #14
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    OK then, I'll try that. But I still want to use DirectDraw, so if anyone wants to make a blank fullscreen or fix the above code, go right ahead.
    Last edited by Driveway; 05-19-2002 at 02:40 PM.

  15. #15
    Here's a code example from "Game programming for dummies". Don't tell anyone of the copyright violation here

    All it does is display a black screen. You should hear your screan make a blip when it changes to 640x480
    I'll also add a second example that will draw pixels on the screen
    Tell me if these examples work.
    Code:
    // PROG9_1.CPP - Creates a DirectDraw object, changes display
    // and creates a primary surface, notice the change in 
    // the window creation flags this time
    
    // INCLUDES ///////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN  
    
    #include <windows.h>   // include important windows stuff
    #include <windowsx.h> 
    #include <mmsystem.h>
    #include <iostream.h> // include important C/C++ stuff
    #include <conio.h>
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <string.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <math.h>
    #include <io.h>
    #include <fcntl.h>
    
    #include <ddraw.h>  // directX includes
    
    // DEFINES ////////////////////////////////////////////////
    
    // defines for windows 
    #define WINDOW_CLASS_NAME "WINXCLASS"  // class name
    
    #define WINDOW_WIDTH  640              // size of window
    #define WINDOW_HEIGHT 480
    #define SCREEN_WIDTH  640              // size of screen
    #define SCREEN_HEIGHT 480
    #define SCREEN_BPP    8                // bits per pixel
    
    // MACROS /////////////////////////////////////////////////
    
    // these read the keyboard asynchronously
    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    
    // TYPES //////////////////////////////////////////////////
    
    typedef unsigned short USHORT;
    typedef unsigned short WORD;
    typedef unsigned char  UCHAR;
    typedef unsigned char  BYTE;
    
    // PROTOTYPES /////////////////////////////////////////////
    
    int Game_Init(void *parms=NULL);
    int Game_Shutdown(void *parms=NULL);
    int Game_Main(void *parms=NULL);
    
    // GLOBALS ////////////////////////////////////////////////
    
    HWND main_window_handle = NULL; // save the window handle
    HINSTANCE main_instance = NULL; // save the instance
    char buffer[80];                // used to print text
    
    LPDIRECTDRAW         lpdd         = NULL;  // dd object
    LPDIRECTDRAWSURFACE  lpddsprimary = NULL;  // dd primary surface
    LPDIRECTDRAWSURFACE  lpddsback    = NULL;  // dd back surface
    LPDIRECTDRAWPALETTE  lpddpal      = NULL;  // a pointer to the created dd palette
    DDSURFACEDESC        ddsd;                 // a direct draw surface description struct
    DDSCAPS              ddscaps;              // a direct draw surface capabilities struct
    HRESULT              ddrval;               // result back from dd calls
    
    // FUNCTIONS //////////////////////////////////////////////
    
    LRESULT CALLBACK WindowProc(HWND hwnd, 
    						    UINT msg, 
                                WPARAM wparam, 
                                LPARAM lparam)
    {
    // this is the main message handler of the system
    PAINTSTRUCT	ps;		   // used in WM_PAINT
    HDC			hdc;	   // handle to a device context
    
    // what is the message 
    switch(msg)
    	{	
    	case WM_CREATE: 
            {
    		// do initialization stuff here
    		return(0);
    		} break;
    
        case WM_PAINT:
             {
             // start painting
             hdc = BeginPaint(hwnd,&ps);
    
             // end painting
             EndPaint(hwnd,&ps);
             return(0);
            } break;
    
    	case WM_DESTROY: 
    		{
    		// kill the application			
    		PostQuitMessage(0);
    		return(0);
    		} break;
    
    	default:break;
    
        } // end switch
    
    // process any messages that we didn't take care of 
    return (DefWindowProc(hwnd, msg, wparam, lparam));
    
    } // end WinProc
    
    // WINMAIN ////////////////////////////////////////////////
    
    int WINAPI WinMain(	HINSTANCE hinstance,
    					HINSTANCE hprevinstance,
    					LPSTR lpcmdline,
    					int ncmdshow)
    {
    
    WNDCLASS winclass;	// this will hold the class we create
    HWND	 hwnd;		// generic window handle
    MSG		 msg;		// generic message
    HDC      hdc;       // generic dc
    PAINTSTRUCT ps;     // generic paintstruct
    
    // first fill in the window class stucture
    winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                              CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc	= WindowProc;
    winclass.cbClsExtra		= 0;
    winclass.cbWndExtra		= 0;
    winclass.hInstance		= hinstance;
    winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground	= GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName	= NULL; 
    winclass.lpszClassName	= WINDOW_CLASS_NAME;
    
    // register the window class
    if (!RegisterClass(&winclass))
    	return(0);
    
    // create the window, note the use of WS_POPUP
    if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
    						  "WinX Game Console",	 // title
    						  WS_POPUP | WS_VISIBLE,
    					 	  0,0,	   // x,y
    						  WINDOW_WIDTH,  // width
                              WINDOW_HEIGHT, // height
    						  NULL,	   // handle to parent 
    						  NULL,	   // handle to menu
    						  hinstance,// instance
    						  NULL)))	// creation parms
    return(0);
    
    // save the window handle and instance in a global
    main_window_handle = hwnd;
    main_instance      = hinstance;
    
    // perform all game console specific initialization
    Game_Init();
    
    // enter main event loop
    while(1)
    	{
    	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    		{ 
    		// test if this is a quit
            if (msg.message == WM_QUIT)
               break;
    	
    		// translate any accelerator keys
    		TranslateMessage(&msg);
    
    		// send the message to the window proc
    		DispatchMessage(&msg);
    		} // end if
        
        // main game processing goes here
        Game_Main();
    
    	} // end while
    
    // shutdown game and release all resources
    Game_Shutdown();
    
    // return to Windows like this
    return(msg.wParam);
    
    } // end WinMain
    
    // WINX GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
    
    int Game_Init(void *parms)
    {
    // this function is where you do all the initialization 
    // for your game
    
    // create object and test for error
    if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
       return(0);
    
    // set cooperation level to windowed mode normal
    if (lpdd->SetCooperativeLevel(main_window_handle,
               DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
               DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK)
        return(0);
    
    // set the display mode
    if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP)!=DD_OK)
       return(0);
    
    // Create the primary surface
    memset(&ddsd,0,sizeof(ddsd));
    ddsd.dwSize         = sizeof(ddsd);
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    
    if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
       return(0);
    
    // return success
    return(1);
    } // end Game_Init
    
    ///////////////////////////////////////////////////////////
    
    int Game_Shutdown(void *parms)
    {
    // this function is where you shutdown your game and
    // release all resources that you allocated
    
    // first release the primary surface
    if (lpddsprimary!=NULL)
       lpddsprimary->Release();
           
    // release the directdraw object
    if (lpdd!=NULL)
       lpdd->Release();
    
    // return success
    return(1);
    } // end Game_Shutdown
    
    ///////////////////////////////////////////////////////////
    
    int Game_Main(void *parms)
    {
    // this is the workhorse of your game it will be called
    // continuously in real-time this is like main() in C
    // all the calls for you game go here!
    
    // check of user is trying to exit
    if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
        PostMessage(main_window_handle, WM_DESTROY,0,0);
    
    // return success
    return(1);
    } // end Game_Main

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 12:16 PM
  2. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  3. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  4. DirectX 8 with Borland
    By Tommaso in forum Game Programming
    Replies: 11
    Last Post: 08-12-2003, 09:30 AM
  5. Directx SDK Documentation
    By Zoalord in forum Game Programming
    Replies: 4
    Last Post: 05-08-2003, 06:07 AM