HQ NETWORK:   XBOX ONE |  XBOX 360 |  AIDELUXE HQ Network: 1,377 | Guests: 270 | Members: 0 


   Current Location: Forums Original Xbox HELP NEEDED   |   Port forwarding for Xbox   |   New Game - Fursan al-Aqsa - Knights of al-Aqsa Mosque   |   Help DuoX2 AMD Boot!!!   |   Help and advice!   |   Softmod Installer Deluxe 6 (SID6) Out Now [2020]   |   PANGEON Xbox One Game Giveaway - Enter Now!   |   Minimalist UnleashX Skin   |   New google drive   |   Error code 09   |   
  Home | Active Topics | CD/DVD Media | Downloads | Forums | Feedback | Games | HardDrives | Homebrew | My Profile | ModChips | Reviews | Search | SoftMods | Tutorials

Xbox Forums

Discuss all aspects of the original Xbox Console in our Interactive Xbox Forums..

Pre-order Microsoft Flight Simulator
Xbox-Hq.Com :: View topic - Prt2 - "DirectX Initilisation"
Xbox-Hq.Com Forum Index -> Xbox Programming
Post new topic Reply to topic    
 Prt2 - "DirectX Initilisation" View previous topic :: View next topic  
 
 
 
 
forahobby
Administrator
Administrator


Joined: May 22, 2003
Posts: 23728
Location: NSW, Australia

Post Posted: Sat Nov 13, 2004 2:16 pm   
Post subject: Prt2 - "DirectX Initilisation"
Reply with quote
 
Well you can't go through life just adding in a few lines of code that do nothing - so now for some juicy code you can look at. Don't be scared, this code we learn once, put it in an init() function and we can just call it whenever we start using directX.

The code more or less stays the same. From now on you'll be able to cut and copy this code into further projects, or as I usually do, put it in a init.cpp file.
Code:
//Main header file for the XDK
#include <xtl.h>

//Application entry point
void __cdecl main()
{
      InitialiseD3D();
      while(true)
      {

            //Clear the backbuffer to black
                //                                                      r   g   b
            g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,  0, 255), 1.0f, 0);

            //Begin the scene
            g_pD3DDevice->BeginScene();

            //End the scene
            g_pD3DDevice->EndScene();

            //Filp the back and front buffers so that whatever has been rendered on the back buffer
            //will now be visible on screen (front buffer).
            g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
      }     
      CleanUp();
}

DirectX Initialisation code, which usually remains the same. i.e. you could put it in a separate file and just add it to each new project you create.
Code:

LPDIRECT3D8 g_pD3D = NULL;                      // DirectX Object
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;          // Screen Object

void InitialiseD3D()
{
    //First of all, create the main D3D object. If it is created successfully we
    //should get a pointer to an IDirect3D8 interface.
    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);

    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    //Fill the structure.
    // Set fullscreen 640x480x32 mode
      d3dpp.BackBufferWidth = 640;
      d3dpp.BackBufferHeight = 480;
      d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;

      // Create one backbuffer
      d3dpp.BackBufferCount = 1;

      // Set up how the backbuffer is "presented" to the frontbuffer each   time
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

    //Create a Direct3D device.
    g_pD3D->CreateDevice(0, D3DDEVTYPE_HAL, NULL,
                                   D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                                   &d3dpp, &g_pD3DDevice);
}
void CleanUp()
{
    g_pD3DDevice->Release();
    g_pD3D->Release();
}

So what happens - well when you run this little snippet of code don't expect to much. It just shows you the pieces that make up directX. It initilises directX then renders the screen (e.g. clears it blue). A blue screen is all you get when you run this little snippet of code.

Well thats it, you should be able to look at this code and understand it. I've not details a lot of the small stuff, because I'll come back and do it later. For example - in g_pD3D->CreateDevice(0, D3DDEVICE_HAL, NULL, .., .., ..). The D3DDEVICE_HAL informs directX to use hardware for the computations.

_________________
HQ Network:
www.xbox-hq.com | www.xboxone-hq.com | www.360-hq.com | www.c64-hq.com


View user's profile Send private message Send e-mail Visit poster's website
 
Display posts from previous:   
  Post new topic  
 
  Reply to topic  
|
 All times are GMT | Page 1 of 1
Jump to:  
 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
 

 Members Online (0) / Guests Online (270)
Members Browsing


Legend
Administrator  Moderator  VIP Member  Registered User  Banned Users

Pre-order Microsoft Flight Simulator