Jump to content
  • Advertisement
Sign in to follow this  
RedRabbit

Frustrating errors! Please help!

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

NEVERMIND
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(17): error C2146: syntax error : missing ';' before identifier 'InitializeD3D'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(53): error C2146: syntax error : missing ';' before identifier 'InitializeVertexBuffer'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(53): error C2371: 'HRESULT' : redefinition; different basic types
        c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(17) : see declaration of 'HRESULT'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(17): error C2377: 'HRESULT' : redefinition; typedef cannot be overloaded with any other symbol
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinNT.h(354) : see declaration of 'HRESULT'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(53): error C2501: 'HRESULT' : missing storage-class or type specifiers
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(47): error C2617: 'InitializeD3D' : inconsistent return statement
        c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(17) : see declaration of 'InitializeD3D'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(50): error C2617: 'InitializeD3D' : inconsistent return statement
        c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(17) : see declaration of 'InitializeD3D'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(78): error C2617: 'InitializeVertexBuffer' : inconsistent return statement
        c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(53) : see declaration of 'InitializeVertexBuffer'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(87): error C2617: 'InitializeVertexBuffer' : inconsistent return statement
        c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(53) : see declaration of 'InitializeVertexBuffer'
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(76): error C2664: 'IDirect3DVertexBuffer8::Lock' : cannot convert parameter 3 from 'void **__w64  ' to 'BYTE ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(70): error C2676: binary '<' : 'CUSTOMVERTEX' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(76): error C2676: binary '<' : 'CUSTOMVERTEX' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(191): error C2676: binary '>=' : 'CUSTOMVERTEX' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(193): error C2676: binary '>=' : 'CUSTOMVERTEX' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(156): error C3861: 'Cleanup': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(70): error C3861: 'HRESULT': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(76): error C3861: 'HRESULT': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(191): error C3861: 'HRESULT': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Mike\Desktop\Projects\DXWindow\DXWindow\main.cpp(193): error C3861: 'HRESULT': identifier not found, even with argument-dependent lookup




#include <d3d8.h>

LPDIRECT3D8 g_pD3D = NULL;
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;
LPDIRECT3DVERTEXBUFFER8 g_pVertexBuffer = NULL;	//Buffer that holds vertices

struct CUSTOMVERTEX
{
	FLOAT x,y,z,rhw;	//Transformed position for the vertex
	DWORD color;		//Vertex Color
}

#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
#define SafeRelease(pObject) if(pObject != NULL) { pObject->Release(); pObject = NULL;}


HRESULT InitializeD3D(HWND hWnd)
{
    //First of all, create the main D3D object. If it is created successfully we
    //should get a pointer to an IDirect3D8 interface.
    g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
	if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION)))
		return 0;

	//Get the current display mode
    D3DDISPLAYMODE d3ddm;
    if(NULL == (g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
    {
        return 0;
    }

    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    //Fill the structure.
    //We want our program to be windowed, and set the back buffer to a format
    //that matches our current display mode
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

    //Create a Direct3D device.
    if(NULL == (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
    {
        return;
    }
    
    return;
}

HRESULT InitializeVertexBuffer()
{
	VOID* pVertices;

	CUSTOMVERTEX cvVertices[] = 
	{
		//Vertex 1 - Red @ 250,100
		{250.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255,0,0),},
		//Vertex 2 - Green @ 400, 350
		{400.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,255,0),},
		//Vertex 3 - Blue @ 100, 350
		{100.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0,0,255),},
	};

	//Create the buffer from our device (vid card)

	if(FAILED(g_pD3DDevice->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer)))
	{
		return 0;
	}

	//Get a pointer to the vertex buffer vertices then lock the vertex buffer
	if(FAILED(g_pVertexBuffer->Lock(0,sizeof(cvVertices), (void**)&pVertices,0)))
	{
		return;
	}

	//Copy our vertices values into the vertex buffer
	memcpy(pVertices, cvVertices, sizeof(cvVertices));

	//Unlock the vertex buffer
	g_pVertexBuffer->Unlock();

	return;
}

void Render()
{
    if(g_pD3DDevice == NULL)
    {
        return;
    }

    //Clear the backbuffer to a green color
	 g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
    
    //Begin the scene
    g_pD3DDevice->BeginScene();
    
    //Rendering the triangle
	g_pD3DDevice->SetStreamSource(0,g_pVertexBuffer,0,sizeof(CUSTOMVERTEX));
    g_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    //End the scene
    g_pD3DDevice->EndScene();
    
    //Flip the back and front buffers so that whatever has been rendered on the back buffer
    //will now be visible on screen (front buffer).
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
    SafeRelease(g_pVertexBuffer);
	SafeRelease(g_pD3DDevice);
	SafeRelease(g_pD3D);
}

void GameLoop()
{
    //Enter the game loop
    MSG msg;
    BOOL fMessage;

    PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
    
    while(msg.message != WM_QUIT)
    {
        fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

        if(fMessage)
        {
            //Process message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            //No message to process, so render the current scene
            Render();
        }

    }
}

//The windows message handler
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
			Cleanup();
            PostQuitMessage(0);
            return 0;
        break;
        case WM_KEYUP:
            switch (wParam)
            {
                case VK_ESCAPE:
                    //User has pressed the escape key, so quit
                    DestroyWindow(hWnd);
                    return 0;
                break;
            }
        break;

    }

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

//Application entry point
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
    //Register the window class
    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                     GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                     "DX Project 2", NULL};
    RegisterClassEx(&wc);

    //Create the application's window
    HWND hWnd = CreateWindow("DX Project 2", "Tutorial 2 - Triangles",
                              WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL);

    //Initialize Direct3D
    if(SUCCEEDED(InitializeD3D(hWnd)))
    {
		if(SUCCEEDED(InitializeVertexBuffer()))
		{
        //Show our window
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);
		
		//Initialize Vertex Buffer
		
        //Start game running: Enter the game loop
        GameLoop();
		}
    }
    
    CleanUp();

    UnregisterClass("DX Project 2", wc.hInstance);
    
    return 0;
}



Share this post


Link to post
Share on other sites
Advertisement
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!