d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Problem With Build Up Directx > Into A Class
Add Reply New Topic New Poll
Member
Posts: 4,065
Joined: Oct 4 2007
Gold: 4.19
Warn: 10%
Mar 26 2013 02:11am
So I made the following header and cpp files:

Main.cpp: contains simple directX calls initD3D(), render_frame() and cleanD3D() where they have to.... and a dx_manager included where i set up other things (thats below...)

Quote
// ProbaEngine.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "ProbaEngine.h"
#include "dx_manager.h"

#define MAX_LOADSTRING 100

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                  HINSTANCE hPrevInstance,
                  LPSTR lpCmdLine,
                  int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300, 300,
                          800, 600,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    initD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT)
            break;

      render_frame();
    }

    // clean up DirectX and COM
    cleanD3D();

    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }

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


dx_manager.h : contains globals

Quote
#pragma once
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")

class dx_manager
{
LPDIRECT3D9 d3d;   
LPDIRECT3DDEVICE9 d3ddev;
void cleanD3D(void);    // closes Direct3D and releases memory
public:
dx_manager(void);
~dx_manager(void);
void initD3D(HWND hWnd);    // sets up and initializes Direct3D
void render_frame(void);    // renders a single frame
void BeginScene();
void EndScene();
};
extern dx_manager g_dxManager;


and dx_manager.cpp: that contains functions

Quote
#include "StdAfx.h"
#include "dx_manager.h"

dx_manager::dx_manager(void)
{
d3d = NULL;
d3ddev = NULL;
}

dx_manager::~dx_manager(void)
{
cleanD3D();
}

void dx_manager::initD3D(HWND hWnd)
{
  d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D

    // create a device class using this information and information from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
}

void dx_manager::render_frame()
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);    // displays the created frame
}

void dx_manager::cleanD3D()
{
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D
}


at the end i have 3 errors on initD3D(), render_frame and cleanD3D -> identifier not found

it should work...or not?

This post was edited by lowxair on Mar 26 2013 02:14am
Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Mar 26 2013 04:39am
well i cant compile it because i dont have the "h" file of the engine.

but if i look at the code, i don't see any reason why the compiler could know which "initD3D(hWnd)" function he should use. usually you create classes and then you can call their methods. if you call a method of any class, how can the compiler know which classe's method you mean?
Code
example, you got these:
door::open()
window::open()
and now you call this:
open()
what happens?


i havent coded c++ for a while (so maybe i'm completely wrong), but what happens if you create a class first, on which you can execute this method? or at least try to use the class "within the right namespace": "dx_manager::initD3D(hWnd);" (but i guess that doesn't work)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll