9 Replies - 909 Views - Last Post: 16 June 2013 - 07:17 AM Rate Topic: -----

#1 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

DirectX Head Scratcher

Posted 12 June 2013 - 03:32 PM

Hey there all, as some of you know I am a game programmer in progress (and I stress progress). I have built an extremely small text based console game. Now I am trying to upgrade it, I decided to do what I thought was the biggest first, the graphics. So I followed some tutorials, but on the lesson on loading bitmaps I've a head scratcher for me. The code will compile correctly but the program comes up for half a second and ends. Here is my code:

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>
#include <iostream>
using namespace std;

const string APPTITLE = "Load BitMap Program";
 
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

#define SCREENW 1024
#define SCREENH 768

LPDIRECT3D9 d3d = NULL; 
LPDIRECT3DDEVICE9 d3ddev = NULL; 
LPDIRECT3DSURFACE9 backbuffer = NULL;
LPDIRECT3DSURFACE9 surface = NULL;

bool gameover = false;

bool Game_Init(HWND hwnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (!d3d)
    {
        MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK);
        return false;
    }

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = SCREENW;
    d3dpp.BackBufferHeight = SCREENH;
    d3dpp.hDeviceWindow = hwnd;

    d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

    if (!d3ddev)
    {
        MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK);
        return false;
    }

    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
    
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    HRESULT result = d3ddev->CreateOffscreenPlainSurface(
        SCREENW,                
        SCREENH,                
        D3DFMT_X8R8G8B8,    
        D3DPOOL_DEFAULT,    
        &surface,           
        NULL);              

    if (!SUCCEEDED(result)) return false;

	result = D3DXLoadSurfaceFromFile(
		surface,NULL,
		NULL,
		"grassgraphics.bmp",
		NULL,
		D3DX_DEFAULT,
		0,
		NULL);

	if (!SUCCEEDED(result)) return false;


    return true;
}

void Game_Run(HWND hwnd)
{
    if (!d3ddev) return;

	d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO,&backbuffer);

    if (d3ddev->BeginScene())
    {
		d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE);
    
        d3ddev->EndScene();

        d3ddev->Present(NULL, NULL, NULL, NULL);
    }

    if (KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY, 0, 0);
}


void Game_End(HWND hwnd)
{
    if (surface) surface->Release();
    if (d3ddev) d3ddev->Release();
    if (d3d) d3d->Release();
}



LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            gameover = true;
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE.c_str();
    wc.hIconSm       = NULL;
    RegisterClassEx(&wc);

    HWND window = CreateWindow(APPTITLE.c_str(), APPTITLE.c_str(), 
       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
       SCREENW, SCREENH, NULL, NULL, hInstance, NULL);

    if (window == 0) return 0;

	ShowWindow(window, nCmdShow);
    UpdateWindow(window);
    
    if (!Game_Init(window)) return 0;


    MSG message;
    while (!gameover)
    {
        if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) 
        {
            TranslateMessage(&message);
            DispatchMessage(&message);
        }

        Game_Run(window);
    }

    return message.wParam;
}




I followed this tutorial to link directx to my program (this gave me some trouble when I started):

http://thelearningga...rectx9-sdk.html

My bitmap is just a jpeg picture that I converted. If you guys happen to know what the malfunction is in my code please point it out, if there isn't a problem with the code the could someone explain to me why this happens. Thanks for all the help. :)/>

Is This A Good Question/Topic? 0
  • +

Replies To: DirectX Head Scratcher

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DirectX Head Scratcher

Posted 13 June 2013 - 08:23 AM

What is the exception if there is any, or does it just bomb out? If it does just bomb compile the code and run in debug for a description of what the problem is.
Was This Post Helpful? 0
  • +
  • -

#3 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: DirectX Head Scratcher

Posted 13 June 2013 - 11:03 AM

View PostButchDean, on 13 June 2013 - 10:23 AM, said:

What is the exception if there is any, or does it just bomb out? If it does just bomb compile the code and run in debug for a description of what the problem is.


I'm not sure what your question is, like I said it compiles properly (I think) but the program just shuts down before I can see it. Here is the output codes that come up after I compile and run the program.


'bitmap.exe': Loaded 'C:\Users\Jesse's\Documents\Visual Studio 2010\Projects\bitmap\Debug\bitmap.exe', Symbols loaded.
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\d3d9.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\d3d8thk.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\D3DX9_43.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\ProgramData\Wincert\win32cert.dll', Cannot find or open the PDB file
'bitmap.exe': Unloaded 'C:\ProgramData\Wincert\win32cert.dll'
The thread 'Win32 Thread' (0xf68) has exited with code 1579358290 (0x5e231852).
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\igdumdx32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\igdumd32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'bitmap.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x15c4) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x824) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x674) has exited with code 0 (0x0).
The program '[3380] bitmap.exe: Native' has exited with code 0 (0x0).




hope this will help clear up any questions on my previous post.
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DirectX Head Scratcher

Posted 13 June 2013 - 11:30 AM

Are you running release or debug mode in Visual studio?
Was This Post Helpful? 0
  • +
  • -

#5 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: DirectX Head Scratcher

Posted 13 June 2013 - 12:23 PM

View PostButchDean, on 13 June 2013 - 01:30 PM, said:

Are you running release or debug mode in Visual studio?


I believe it was debug, when it was changed to release I got this error code:


..\..\..\..\..\..\Jesse's\documents\visual studio 2010\Projects\bitmap\bitmap\main.cpp(3): fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory




maybe I forgot to change something while linking it, I check that firsts. Thanks for that question to point my mind in a new direction. :)/>
Was This Post Helpful? 0
  • +
  • -

#6 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: DirectX Head Scratcher

Posted 13 June 2013 - 12:33 PM

View PostDelacar, on 13 June 2013 - 02:23 PM, said:

View PostButchDean, on 13 June 2013 - 01:30 PM, said:

Are you running release or debug mode in Visual studio?


I believe it was debug, when it was changed to release I got this error code:


..\..\..\..\..\..\Jesse's\documents\visual studio 2010\Projects\bitmap\bitmap\main.cpp(3): fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory




maybe I forgot to change something while linking it, I check that firsts. Thanks for that question to point my mind in a new direction. :)/>/>



nope, same problem.
Was This Post Helpful? 0
  • +
  • -

#7 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1011
  • View blog
  • Posts: 4,215
  • Joined: 14-February 08

Re: DirectX Head Scratcher

Posted 15 June 2013 - 04:07 PM

Have you stepped through your code to see where it may be crashing? I bet it's not making it into that while loop.
Was This Post Helpful? 0
  • +
  • -

#8 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: DirectX Head Scratcher

Posted 15 June 2013 - 09:06 PM

View Poststayscrisp, on 15 June 2013 - 06:07 PM, said:

Have you stepped through your code to see where it may be crashing? I bet it's not making it into that while loop.


No I have not, but I'm not sure that will help me. I bought a book for game programming in c++ and it came with a cd with all the codes from the book. When I copy and paste in the code from the cd it does the same thing. This is very confusing to me, in theory there should not be a problem. The lesson before this one (in my book) worked great and ran perfectly. Not sure if this has any bearing on the situation but I am using Visual Studio 2010 Express, the DXSDK June 10 download, and the windows operating system, shouldn't but hey I am very new to graphics for games and I'm runnoing many possibilities.
Was This Post Helpful? 0
  • +
  • -

#9 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1011
  • View blog
  • Posts: 4,215
  • Joined: 14-February 08

Re: DirectX Head Scratcher

Posted 16 June 2013 - 01:55 AM

I am positive that it will help you. Even books have code errors or incompatible code.

Step through each line of your code and you will see exactly where something is going wrong, you can then try and work out why (or ask why) and you will have learned something.
Was This Post Helpful? 1
  • +
  • -

#10 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: DirectX Head Scratcher

Posted 16 June 2013 - 07:17 AM

Agreed. Forums don't substitute for debug skills - the sooner you realize that the better.

Please see the Bruce Lee quote in my sig.

This post has been edited by ButchDean: 16 June 2013 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1