Sign in to follow this  
Makoy

some errors on my first DX program

Recommended Posts

Makoy    126
Hello! This is my first sprite program using dx9 and c++. I have this errors that I can't seem to figure out! A little help will mean so much to me. I hope you dx gurus out there can help me on this. thanks in advance :)
[sourcecode]
#include <windows.h>
#include <stdio.h>
#include <d3dx9core.h>
#include <d3d9.h>
#include <d3dx9.h>

const char g_szClassName[] = "myWindowClass";

class CMainFrame
{
protected:
	IDirect3DTexture9* m_pTitleTexture;
	ID3DXSprite* m_pTitleSprite;   

	IDirect3DDevice9*	m_pd3dDevice;		

public:
	CMainFrame(IDirect3DDevice9*);
	~CMainFrame() {}

	void Render( void );
	HRESULT RestoreDeviceObjects( void );
	HRESULT InvalidateDeviceObjects(void);
	HRESULT Release(void);

};


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
	case WM_PAINT:
		{
			void CMainFrame::Render( void )
		}
		return 0;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Makoy's window",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    	
	return Msg.wParam;
}

CMainFrame::CMainFrame(IDirect3DDevice9* pDevice)
{
	m_pd3dDevice = pDevice;
	m_pTitleSprite = NULL;

	D3DSURFACE_DESC desc;
	desc = *DXUTGetBackBufferSurfaceDesc();

	D3DXCreateSprite( m_pd3dDevice, &m_pTitleSprite );
	D3DXCreateTextureFromFile(m_pd3dDevice, L"sball.png", &m_pTitleTexture);

}

void CMainFrame::Render( void )
{

	const RECT r1 = {0,0,500,200};
	m_pTitleSprite->Begin(D3DXSPRITE_ALPHABLEND);
	m_pTitleSprite->Draw(m_pTitleTexture, &r1, NULL, NULL, 0xFFFFFFFF);
	m_pTitleSprite->End();

}

HRESULT CMainFrame::RestoreDeviceObjects( void )
{
	if(m_pTitleSprite)
		m_pTitleSprite->OnResetDevice();
	return TRUE;
}

HRESULT CMainFrame::InvalidateDeviceObjects(void)
{
	if( m_pTitleSprite )
		m_pTitleSprite->OnLostDevice();
	return TRUE;
}

HRESULT CMainFrame::Release(void)
{
	SAFE_RELEASE( m_pTitleSprite);
	SAFE_RELEASE( m_pTitleTexture );
	return TRUE;
}
[/sourcecode]
--------------------Configuration: sprite - Win32 Debug-------------------- Compiling... main.cpp C:\projects\sprite\main.cpp(39) : error C2143: syntax error : missing ';' before '}' C:\projects\sprite\main.cpp(110) : error C2065: 'DXUTGetBackBufferSurfaceDesc' : undeclared identifier C:\projects\sprite\main.cpp(110) : error C2100: illegal indirection C:\projects\sprite\main.cpp(113) : error C2664: 'D3DXCreateTextureFromFileA' : cannot convert parameter 2 from 'unsigned short [10]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\projects\sprite\main.cpp(121) : error C2065: 'D3DXSPRITE_ALPHABLEND' : undeclared identifier C:\projects\sprite\main.cpp(122) : error C2660: 'Draw' : function does not take 5 parameters C:\projects\sprite\main.cpp(143) : error C2065: 'SAFE_RELEASE' : undeclared identifier Error executing cl.exe. main.obj - 7 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Trip99    577
This line is dodgy (I guess it is line 39):

void CMainFrame::Render( void )

It looks like a function definition - are you meanding to call this function e.g. CMainFrame::Render(); if so note this would be calling a static function defined in the CMainFrame class where as the fn is not declared static. So you are going to need an instance of the CMainFrame class and then call the function using that,

Share this post


Link to post
Share on other sites
Makoy    126
Quote:

if so note this would be calling a static function defined in the CMainFrame class where as the fn is not declared static. So you are going to need an instance of the CMainFrame class and then call the function using that,


hi trip I'm confused. Can you give me a clue or at least a piece of code to fix it? thanks

Share this post


Link to post
Share on other sites
steg    390
Line 39 is incorrect. I guess it should just be :

Render();

But as Render() is a method in CMainFrame, you first need to have created an instance of this class.

You could do this globally either on the stack or heap.

The constructor for CMainFrame needs a pointer to IDirect3DDevice9, so, say if you have this you could do this :

CMainFrame* pMainFrame = new CMainFrame( pd3dDevice );

Then in your WM_PAINT message you could do :

pMainFrame->Render();

Hope this helps you some ?

Regards,
Steve



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this