Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

Hello give you a simple D3D program .Edited:Let 's make contest

This topic is 4833 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

#include <d3d9.h>
main()
{
IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION);
IDirect3DDevice9 * d = 0;
D3DPRESENT_PARAMETERS d3dpp;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0  , D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d);
}






Are there anyone can do more simple? [Edited by - luasitdown on August 21, 2005 5:58:46 PM]

Share this post


Link to post
Share on other sites
Advertisement
You must fill in the D3DPRESENT_PARAMETERS struct at least, like so:


D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;




See here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
You must fill in the D3DPRESENT_PARAMETERS struct at least, like so:

*** Source Snippet Removed ***

See here.



I know I mean write a most simple D3D code that can run without error.

who can do more simple???

Share this post


Link to post
Share on other sites

#include <d3d9.h>
#include <conio.h>
//#include <windows.h>

LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM w,LPARAM l)
{
return DefWindowProc(hwnd, msg ,w , l);
}

HWND createWin()
{
//
// Create the main application window.
//

WNDCLASS wc;

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(0);
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "Direct3D9App";

if( !RegisterClass(&wc) )
{
::MessageBox(0, "RegisterClass() - FAILED", 0, 0);
return false;
}


HWND hwnd = ::CreateWindow("Direct3D9App", "&#24352;&#38632;",
WS_EX_TOPMOST,
0, 0, 800, 600,
0 /*parent hwnd*/,
0 /* menu */,
GetModuleHandle(0),
0 /*extra*/);

if( !hwnd )
{
::MessageBox(0, "CreateWindow() - FAILED", 0, 0);
return false;
}



::ShowWindow(hwnd, SW_SHOW);
::UpdateWindow(hwnd);
return hwnd;
}

main()
{
HWND hwnd = createWin();
IDirect3D9 * d3d = Direct3DCreate9(D3D_SDK_VERSION);
IDirect3DDevice9 * d = 0;

D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Windowed = 1;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0 , D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d);
d->Clear(0, 0, D3DCLEAR_TARGET||D3DCLEAR_ZBUFFER, 0x0, 1, 0);
d->Present(0,0,0,0);
getch();
}





Let 's make contest
who can do a black screen by D3D with least code?
I offer first code.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!