Jump to content
  • Advertisement
Sign in to follow this  
bionic_atom

OpenGL Starting DirectX but need guidence Please!

This topic is 4405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, Im just now starting DirectX with C++, so yeah im a beginner, but not afraid of all the math since Im in Calc II, and Linear Algebra. However, I downloaded Dev C++ (beta) from www.bloodshed.net and started with some OpenGL tutorials since I couldn't find any Direct X ones; which should I use? I just wanna start making some 3D stuff, but wouldn't want to learn 2 different 3D API's if I wanted to continue this right? Well, could someone please direct me to a good Direct X tutorial startup and a dang compiler that will be easy start with as well. I just got an error the first time, and don't really know how to start a debug if that's the first tutorial on setting up the OpenGL. Can I get help please? I just wanna learn Direct X some before my programming project next year! Thanks, c.s. finch

Share this post


Link to post
Share on other sites
Advertisement
Hello,
You want to download Microsoft Visual C++ Express edition (google that) which is totally free + The Windows platform SDK.

This wil give you a nice c++ programming facility.

Then you'll want to download and install the DirectX 9 SDK October 2006 release, and use the tutorials included.

Then you'll want to roll your own, using the provided "EmptyProject" which is a very nice starting point for a simple Direct3D application.

Enjoy!

Cheers
JA

Share this post


Link to post
Share on other sites
Hello there Im new to d3d9 and visual C++ 2005,
and it seems to be easy to get going a d3d9 app
here is some code that may help you. Its for vc2005 windows xp d3d9, platform sdk, and you will need to link the libs and that from the sdk as well
a start app. ist not the best but its my first
//-----------------------------------------------------------------------------
// File: Text3D.cpp
//
// Desc: Example code showing how to do text in a Direct3D scene.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
//NTDDI_VERSION >= NTDDI_WINXP


//#define _WIN32_WINNT 0x0410 // 0x0501//
//#define WINVER //0x0410// 0x0501//

#define STRICT

#include <Windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <math.h>
#include <tchar.h>
#include <stdio.h>
#include <D3DX9.h>
#include <d3d9.h>



// LPD3DXMESH m_pMesh3DText;
// LPD3DXFONT m_pd3dxFont;

// TCHAR m_strFont[LF_FACESIZE];
// DWORD m_dwFontSize;

// D3DXMATRIXA16 m_matObj1;
// D3DXMATRIXA16 m_matObj2;




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
//INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
//{
// MessageBoxA(NULL, "Hello New World", "Of programming", MB_OK);
// return 0;
//}

//---------------------------------------------------
//the vertex data
//---------------------------------------------------
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex.
DWORD color; // The vertex color.
};/////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//The structure above specifies the format of the custom vertex type.
//The next step is to define the FVF that describes the contents of the vertices in the vertex buffer.
//The following code fragment defines a FVF that corresponds with the custom vertex type created above.
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)






//Now that the custom vertex format is defined, it is time to initialize the vertices.
//The Vertices sample project does this by calling the application-defined function InitVB
//after creating the required Microsoft® Direct3D® objects. The following code fragment initializes
//the values for three custom vertices.
CUSTOMVERTEX vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0), }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0), },
{ 50.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0), },
};



CUSTOMVERTEX Square_vertices[] =
{
{ 300.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0), }, // x, y, z, rhw, color
{ 600.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,0,255), },
{ 600.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,255,0), },

{ 300.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0), }, // x, y, z, rhw, color

};


//The preceding code fragment fills three vertices with the points of a triangle and
//specifies which color each vertex will emit. The first point is at (150, 50) and
//emits the color red (0xffff0000). The second point is at (250, 250) and emits the
//color green (0xff00ff00). The third point is at (50, 250) and emits the color blue-green
//(0xff00ffff). Each of these points has a depth value of 0.5 and an RHW of 1.0.











//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
char G_WindowClassName[256] = "MainWindow";

LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices
LPDIRECT3DVERTEXBUFFER9 g_pVB_Square = NULL;

_int32 screenx = 0;
_int32 screeny = 0;



//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;

// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferWidth = screenx;
d3dpp.BackBufferHeight = screeny;

// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL ,//devicetype D3DDEVTYPE_FORCE_DWORD D3DDEVTYPE_REF
hWnd,
D3DCREATE_MIXED_VERTEXPROCESSING,//D3DCREATE_HARDWARE_VERTEXPROCESSING,// D3DCREATE_SOFTWARE_VERTEXPROCESSING ,//
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}

// Device state would normally be set here



// Create the vertex buffer. Here we are allocating enough memory
// (from the default pool) to hold all our 3 custom vertices. We also
// specify the FVF, so the vertex buffer knows what data it contains.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}

//not needed now
//After creating a vertex buffer, it is filled with data from the custom vertices
//as shown in the following code fragment.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, vertices, sizeof(vertices) );
g_pVB->Unlock();



///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//square
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB_Square, NULL ) ) )
{
return E_FAIL;
}

//not needed now
//After creating a vertex buffer, it is filled with data from the custom vertices
//as shown in the following code fragment.

if( FAILED( g_pVB_Square->Lock( 0, sizeof(Square_vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, Square_vertices, sizeof(Square_vertices) );
g_pVB_Square->Unlock();



return S_OK;
}




//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if(g_pVB != NULL )
g_pVB->Release();



if(g_pVB_Square != NULL )
g_pVB_Square->Release();

if(g_pd3dDevice != NULL)
g_pd3dDevice->Release();

if(g_pD3D != NULL)
g_pD3D->Release();
}




//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
if( NULL == g_pd3dDevice )
return;




// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0) , 1.0f, 0 );


// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Rendering of scene objects can happen here

// Draw the triangles in the vertex buffer. This is broken into a few
// steps. We are passing the vertices down a "stream", so first we need
// to specify the source of that stream, which is our vertex buffer. Then
// we need to let D3D know what vertex shader to use. Full, custom vertex
// shaders are an advanced topic, but in most cases the vertex shader is
// just the FVF, so that D3D knows what type of vertices we are dealing
// with. Finally, we call DrawPrimitive() which does the actual rendering
// of our geometry (in this case, just one triangle).

g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
//g_pd3dDevice->SetStreamSource( 0, g_pVB_Square, 0, sizeof(CUSTOMVERTEX) );



g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );//D3DPT_TRIANGLELIST D3DPT_POINTLIST D3DPT_TRIANGLEFAN
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1 );

g_pd3dDevice->SetStreamSource( 0, g_pVB_Square, 0, sizeof(CUSTOMVERTEX) );

g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );//D3DPT_TRIANGLELIST D3DPT_POINTLIST D3DPT_TRIANGLEFAN
g_pd3dDevice->DrawPrimitive(D3DPT_POINTLIST, 0, 4 );


// End the scene
g_pd3dDevice->EndScene();
}

// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}




//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}

return DefWindowProc( hWnd, msg, wParam, lParam );
}




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class
WNDCLASSEXA wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
G_WindowClassName, NULL };
RegisterClassEx( &wc );

screenx = GetSystemMetrics(SM_CXSCREEN);
screeny = GetSystemMetrics(SM_CYSCREEN);

// Create the application's window
HWND hWnd = CreateWindow(G_WindowClassName, "TestWindow",
WS_OVERLAPPEDWINDOW,//WS_POPUP,//
0, 0,
screenx,
screeny,
GetDesktopWindow(),
NULL,
wc.hInstance,
NULL );

// Initialize Direct3D
if(SUCCEEDED( InitD3D( hWnd ) ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );

// Enter the message loop
MSG msg;
while(GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

UnregisterClass( G_WindowClassName, wc.hInstance );
return 0;
}



Share this post


Link to post
Share on other sites
Once you've got Visual Studio Express up and running and the DirectX 9.0c SDK installed, check out CodeSampler.com, they have some pretty good tutorials. For further learning just google 'DirectX tutorial' there are plenty.

Here's a link to Code Sampler

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!