Jump to content
  • Advertisement

Ratterbox

Member
  • Content Count

    116
  • Joined

  • Last visited

Community Reputation

157 Neutral

About Ratterbox

  • Rank
    Member
  1. yes you should see a quad, or atleast on my system you do. post your exact code again and we can help you. :) EDIT - Sorry its my mistake. when you create the vertex buffer make sure its 4*sizeof(CUSTOMVERTEX) and not 3. I forgot to change it in my post. Sorry.
  2. Ok, I have tried your code and I have made a version that will show a single textured quad. I had to change some of the initalization stuff just to make it compile because I dont have your WinMain.h file. Also your using SetStreamSource so you should be using DrawPrimitive not DrawPrimitiveUP because that is used of Unprocessed vertices. //#include "stdafx.h" #undef UNICODE #include <windows.h> #include <d3d9.h> #include <d3dx9.h> #define WINDOW_TITLE "Improved DirectX Initialization" #define WINDOW_WIDTH 640 #define WINDOW_HEIGHT 480 #define WINDOWED TRUE // Set up the FVF #define D3DFVF_CUSTOMVERTEX D3DFVF_XYZRHW | D3DFVF_TEX1 LPDIRECT3D9 g_pD3D9 = NULL; LPDIRECT3DDEVICE9 g_pD3DDevice = NULL; D3DDISPLAYMODE g_displayMode; D3DPRESENT_PARAMETERS g_D3Dpp; // make a pointer to where the Texture is IDirect3DTexture9 *g_pTexture; // make a pointer to the vertex buffer IDirect3DVertexBuffer9 *g_pVB; HWND g_hWnd; /*TODO: additional variables*/ //A custom vertex structure struct CUSTOMVERTEX { float x, y, z, rhw; float u, v; }; CUSTOMVERTEX vertices[] = { { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, { 100.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f}, { 0.0f, 100.0f, 0.0f, 1.0f, 0.0, 1.0f}, { 100.0f, 100.0f, 0.0f, 1.0f, 1.0f, 1.0f} }; //your map array declaration char map[12][12] = { {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2}, {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); BOOL BuildPresentationParameters(); void RenderFrame(); #define SAFE_RELEASE(a) if((a)){(a)->Release();(a)=NULL;} int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { // Define the window WNDCLASSEX wcex; wcex.cbSize = sizeof( WNDCLASSEX ); wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon( hInstance, IDI_WINLOGO); wcex.hCursor = LoadCursor( NULL, IDC_ARROW ); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = WINDOW_TITLE; wcex.hIconSm = LoadIcon( hInstance,IDI_WINLOGO ); // Register the window RegisterClassEx( &wcex ); // Create the window g_hWnd = CreateWindow( WINDOW_TITLE, WINDOW_TITLE, (WINDOWED) ? WS_OVERLAPPEDWINDOW : WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, hInstance, 0 ); // Adjust to actual desired size RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT }; AdjustWindowRect( &rect, (WINDOWED) ? WS_OVERLAPPEDWINDOW : WS_POPUP, FALSE ); SetWindowPos( g_hWnd, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE ); ShowWindow( g_hWnd, SW_SHOW ); UpdateWindow( g_hWnd ); // Create Direct3D Object g_pD3D9 = Direct3DCreate9( D3D_SDK_VERSION ); if ( !g_pD3D9 ) { MessageBox( 0, "Direct3DCreate9() - Failed", 0, 0 ); return 0; } // Get display mode g_pD3D9->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_displayMode ); // Check for hardware T&L D3DCAPS9 D3DCaps; g_pD3D9->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &D3DCaps ); DWORD vertexProcessing = 0; if ( D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) { vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING; // Check for pure device if ( D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE ) { vertexProcessing |= D3DCREATE_PUREDEVICE; } } else { vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING; } // Fill out the presentation parameters if ( !BuildPresentationParameters() ) { MessageBox( 0, "Unable to find a valid DepthStencil Format", 0, 0 ); SAFE_RELEASE( g_pD3D9 ); return 0; } // Create the device if ( FAILED( g_pD3D9->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, vertexProcessing, &g_D3Dpp, &g_pD3DDevice ) ) ) { SAFE_RELEASE( g_pD3D9 ); MessageBox( 0, "CreateDevice() - Failed", 0, 0 ); return 0; } /*TODO: additional setup*/ // Setting up your map array // Setting up your D3Ddevice's FVF, turning off lighting, and any rendering values for the device // Create our vertex buffer for rendering polygons at super speed if( FAILED( g_pD3DDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { SAFE_RELEASE( g_pD3D9); MessageBox( 0, "Create Vertex Buffer - Failed", 0, 0 ); return 0; } // Fill the Vertex Buffer void *pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) ) { SAFE_RELEASE( g_pD3D9); MessageBox( 0, "Can't fill Vertex Buffer - Failed", 0, 0 ); return 0; } memcpy( pVertices, vertices, sizeof(vertices) ); g_pVB->Unlock(); // Loading the texture or textures(D3DXCreateTextureFromFile or D3DXCreateTextureFromFileEx) - DONE if ( FAILED( D3DXCreateTextureFromFile( g_pD3DDevice, "..\\engine_data\\grass.bmp", &g_pTexture ) ) ) { SAFE_RELEASE( g_pD3D9 ); MessageBox( 0, "Loading Texture - Failed", 0, 0 ); return 0; } // Main loop MSG msg; while ( 1 ) { // Did we recieve a message? if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT) { break; } TranslateMessage( &msg ); DispatchMessage ( &msg ); } else { RenderFrame(); } } // Give back resources SAFE_RELEASE( g_pD3DDevice ); SAFE_RELEASE( g_pD3D9 ); /*TODO: additional cleanup*/ // Releasing texture(s), similar to what you are already doing with other Direct3D object. - DONE SAFE_RELEASE( g_pTexture ); return 0; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * BuildPresentationParameters Purpose: Builds the D3DPRESENT_PARAMETERS structure using the current window size. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ BOOL BuildPresentationParameters() { ZeroMemory( &g_D3Dpp, sizeof(g_D3Dpp) ); D3DFORMAT adapterFormat = (WINDOWED) ? g_displayMode.Format : D3DFMT_X8R8G8B8; if ( SUCCEEDED( g_pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, adapterFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) ) { g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D24S8; } else if ( SUCCEEDED( g_pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, adapterFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 ) ) ) { g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D24X8; } else if ( SUCCEEDED( g_pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, adapterFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ) ) ) { g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D16; } else { return false; } g_D3Dpp.BackBufferWidth = (WINDOWED) ? 640 : g_displayMode.Width; g_D3Dpp.BackBufferHeight = (WINDOWED) ? 480 : g_displayMode.Height; g_D3Dpp.BackBufferFormat = adapterFormat; g_D3Dpp.BackBufferCount = 1; g_D3Dpp.MultiSampleType = D3DMULTISAMPLE_NONE; g_D3Dpp.MultiSampleQuality = 0; g_D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; g_D3Dpp.hDeviceWindow = g_hWnd; g_D3Dpp.Windowed = WINDOWED; g_D3Dpp.EnableAutoDepthStencil = TRUE; g_D3Dpp.FullScreen_RefreshRateInHz = (WINDOWED) ? 0 : g_displayMode.RefreshRate; g_D3Dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; return TRUE; } // Function to Render the Current Frame void RenderFrame() { g_pD3DDevice->Clear( 0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 100 ), 1.0f, 0 ); g_pD3DDevice->BeginScene(); // Render the frame // selecting the texture(s) you want to draw(SetTexture) // setting up the vertices // drawing the polygons(DrawPrimitiveUP) g_pD3DDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pD3DDevice->SetTexture(0, g_pTexture); g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); g_pD3DDevice->EndScene(); g_pD3DDevice->Present( 0, 0, 0, 0 ); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Summary: Application event handler. Parameters: [in] hWnd - Unique handle to the window. [in] message - Incoming message. [in] wParam - Parameter of the message (unsigned int). [in] lParam - Parameter of the message (long). * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch ( message ) { case WM_DESTROY: PostQuitMessage( 0 ); return 0; case WM_PAINT: if ( g_pD3DDevice ) { RenderFrame(); } ValidateRect( hWnd, 0 ); return 0; case WM_KEYDOWN: switch ( wParam ) { case VK_ESCAPE: PostQuitMessage( 0 ); break; } return 0; } return DefWindowProc( hWnd, message, wParam, lParam ); } If you have MSN then you can add me to your contacts list if you have any more questions. my email is ratterbox@gmail.com EDIT PS - also on a side note WS_EX_TOPMOST is an Extended window style so you use it with CreateWindowEx and it would be the first parameter. [Edited by - Ratterbox on March 17, 2006 10:21:18 PM]
  3. You need to actually change your custom vertex structure to include the rhw, your FVF is D3DFVF_XYZRHW so you should have struct CUSTOMVERTEX { float x, y, z, rhw; DWORD color; }; so then set all rhw to 1.0f when you define your quads.
  4. Ratterbox

    C pointer question

    You need to make SolutionPoint a pointer to the struct that you are using by adding an asterisk - * - after the structtype name and before the variable name. structtype* SolutionPoint; then as bpoint suggested go SolutionPoint = &directionNorth; then to use it go either (*SolutionPoint).StructMember or SolutionPoint->StructMember. Either will work fine.
  5. Hi, Im new to C# and Windows forms and im trying to make a Modeless Windows Form with the style of FixedToolwindow. I can create the Form and show it, but my problem is that I then have two icons in the taskbar during runtime. One for the main application form and one for the toolwindow. I was wondering how to make it so that the Toolwindow is a child of the main form and doesnt have its own icon in the taskbar. Thanks. Edit: Btw Im using C# with Microsoft Visual C# Express Edit: Dont worry. I was being blind when looking through all the properties. Just had to set the ShowInTaskBar Property to false. [Edited by - Ratterbox on February 6, 2006 3:01:21 AM]
  6. Wow, sounds like a good idea. Im a C/C++ programmer that is current developing in main C++ and DirectX. Also learning C# on the side. Anybody feel free to ad me too and ask any questions concerning the subjects above. My MSN is: chatterbox (at) xtra (dot) co (dot) nz.
  7. You may need to change the project type to Windows application. Go into the Project Propetries and change the "Object type" to Windows application. I have found so far that this Console application is the default and gets very annoying very fast.
  8. Could you be more specific? WYSIWYG means What you see is what you get. Its a technique that is usually used in editors and such when printing so that what you see in the editor looks the same as what is printed on a page. So I dont really understand what you mean by a WYSIWYG editor for creating GUIs.
  9. Ratterbox

    Extracting the decimal

    Try (((decimal * 10) % 10) / 10) should give you the decimal only. Imnot sure if % operator is available in shaders, but im sure that there is a function equivilant.
  10. Ratterbox

    CreateWindowEx() - FAILED [SOLVED]

    I think you may be forgetting to actually Register your window class. Your setting up the WNDCLASSEX struct, but you never call RegisterClassEx(). Try adding that in and see if it works.
  11. Ratterbox

    Movment...

    btw, SQRT(2) actually == 1.414, however 1/SQRT(2) == 0.707
  12. Ratterbox

    trig functions using series

    Your power function only works for Natural Numbers (I think thats them, the counting ones), what if you wanted to do something like 25 ^ 0.5 ?? I dont know how to do that myself, but its just a thought
  13. Ratterbox

    Visual C++ 6.0 won't install in SP2

    is your cdrom ( I assume its cd-rom) installation for Windows XP pre-patched?? If it isnt then you could install Windows XP then install VSC++ 6.0 then update it to SP2. I have a funny feeling that it is though otherwise this seems like a very obvious solution. Have you tried running the installation with Windows 98 compatibility running? just throwing a few ideas around.
  14. Ratterbox

    Over riding CFrameWnd::OnClose()

    hrm, sorry, I re-read your question, well ... you dont need to call CFrameWnd::OnClose() to quit the application because all that does is call all the default procedures that MFC has for that function. Instead just use PostQuitMessage to exit but before hand create your custom dialog box, etc, get the response required and then act accordingly. i.e. void MyWindowClass::OnClose() { int Result = MessageBox("Quit?", "Are you sure?", MB_YESNO); if(Result == IDYES) { PostQuitMessage(0); } }
  15. Ratterbox

    Over riding CFrameWnd::OnClose()

    If you want to override the WM_CLOSE handler in MFC first you make a function in your window class like so: void OnClose(); which it seems that you have already done, but you also need to add a notifier to your message map, which is done like so: BEGIN_MESSAGE_MAP(.....) ....... ON_WM_CLOSE() ....... END_MESSAGE_MAP() and when you want to close the application just call PostQuitMessage(0); as you would in a normal windows application
  • 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!