Jump to content
  • Advertisement
Sign in to follow this  
Raxvan

directx 9 lib error

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

i have a problem running only directx 9 programs. the rest of the programs like programs that use directx 8 libraries work fine.even the simple program does not work. pls help or else i will die :P here is a sample of error: --------------------Configuration: DX Project 1 - Win32 Debug-------------------- Compiling... Main.cpp Linking... Main.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4 Debug/DX Project 1.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. DX Project 1.exe - 2 error(s), 0 warning(s) code:
#include <d3d9.h>

LPDIRECT3D9             g_pD3D			= NULL;
LPDIRECT3DDEVICE9       g_pD3DDevice	= NULL;

HRESULT InitialiseD3D(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 = Direct3DCreate9(D3D_SDK_VERSION);
	if(g_pD3D == NULL)
	{
        return E_FAIL;
	}

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

	//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_COPY;
    d3dpp.BackBufferFormat	= d3ddm.Format;

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

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

    //Clear the backbuffer to a green color
    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
    
    //Begin the scene
    g_pD3DDevice->BeginScene();
    
    //Rendering of our game objects will go here
    
    //End the scene
    g_pD3DDevice->EndScene();
    
    //Filp 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()
{
    if(g_pD3DDevice != NULL)
	{
        g_pD3DDevice->Release();
		g_pD3DDevice = NULL;
	}

    if(g_pD3D != NULL)
	{
        g_pD3D->Release();
		g_pD3D = NULL;
	}
}

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:
            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 1", NULL};
    RegisterClassEx(&wc);

    //Create the application's window
    HWND hWnd = CreateWindow("DX Project 1", "www.andypike.com: Tutorial 1", 
                              WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL);

    //Initialize Direct3D
    if(SUCCEEDED(InitialiseD3D(hWnd)))
    { 
        //Show our window
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);

		//Start game running: Enter the game loop
		GameLoop();
    }
    
	CleanUp();

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


10x

Share this post


Link to post
Share on other sites
Advertisement
Hi there Raxvan,
How are you doing?

The Problem
Linking DirectX libraries

The Solution
1) Make sure you have DirectX9 installed.
2) Make sure that you are linking the correct libraries.

If you are using Visual Studio you can use the following to ease the annoying linking of libraries.
e.g.
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx.lib")


I hope this helps buddy :)
take care.

Share this post


Link to post
Share on other sites
i have everything possible installed and
yes tnx now is working but i don't understand the problem. why some programs like sdk/samples work and the rest not?.
and why only programs using directx 9?
and if you look in a tutorial you can't find
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx.lib")
why???

Share this post


Link to post
Share on other sites
Quote:
Original post by Raxvan
i have everything possible installed and
yes tnx now is working but i don't understand the problem. why some programs like sdk/samples work and the rest not?.
and why only programs using directx 9?
and if you look in a tutorial you can't find
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx.lib")
why???


I think it's specific to Visual Studio, that is it won't work on other compilers and isn't a "standard" part of C++ (although the #pragma command itself is, IIRC). I have seen it in tutorials before though, DrunkenHyena used this.

EDIT: Actually, that's probably a stupid possible reason. Maybe you were just looking at a medicore tutorial? Most DirectX tutorials consider the possibility that you're using Visual Studio.

Share this post


Link to post
Share on other sites
Can I ask a similiar question, I've been doing fine with using Direct3D9 but as soon as I try to include Direct3DX I get lots of compiler errors in the header files.

My includes are as follows:
#include <windows.h>  
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <mmsystem.h>
#include <ddraw.h>
#include <fcntl.h>
#include <signal.h>
#include <float.h>
#include <io.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx.lib")

If I comment out #include <d3dx9.h> everything is fine apart from of course I can't use any Direct3DX9 functions/types etc. When I uncomment it I get about 20 errors, all in d3dx9xof.h and d3dx9math.inl:
------ Build started: Project: d3d2, Configuration: Debug Win32 ------

Compiling...
d3d2.cpp
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(992) : error C2065: 'UINT_PTR' : undeclared identifier
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(992) : error C2146: syntax error : missing ')' before identifier 'p'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(992) : error C2059: syntax error : ')'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(1005) : error C2146: syntax error : missing ')' before identifier 'p'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(1005) : error C2059: syntax error : ')'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9math.inl(1005) : error C3861: 'UINT_PTR': identifier not found, even with argument-dependent lookup
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(79) : error C2146: syntax error : missing ';' before identifier 'dSize'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(79) : error C2501: '_D3DXF_FILELOADMEMORY::SIZE_T' : missing storage-class or type specifiers
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(79) : error C2501: '_D3DXF_FILELOADMEMORY::dSize' : missing storage-class or type specifiers
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(163) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(182) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(200) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(204) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(222) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(223) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(242) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(244) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(248) : error C2061: syntax error : identifier 'SIZE_T'
c:\Program Files\Microsoft DirectX 9.0 SDK (Summer 2004)\Include\d3dx9xof.h(249) : error C2061: syntax error : identifier 'SIZE_T'
c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\d3d2.cpp(47) : error C2146: syntax error : missing ';' before identifier 'eye_vector'
c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\d3d2.cpp(47) : error C2501: 'D3DXVECTOR' : missing storage-class or type specifiers
c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\d3d2.cpp(47) : error C2501: 'eye_vector' : missing storage-class or type specifiers
c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\d3d2.cpp(47) : error C2501: 'lookat_vector' : missing storage-class or type specifiers
c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\d3d2.cpp(47) : error C2501: 'up_vector' : missing storage-class or type specifiers

Build log was saved at "file://c:\Documents and Settings\Ray\My Documents\Visual Studio Projects\d3d2\Debug\BuildLog.htm"
d3d2 - 24 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped


Obviously the last 5 are from my code that won't work because of the problems with loading D3DX.

I've got DirectX's lib and include folders set up right in VC++ and haven't had any problems like this with other aspects of DirectX.

Am I missing another lib or .h? As far as I'm aware I have DX installed ok so I don't think it's that.

Thanks

[edit]As the compiler output suggests I'm using the summer 2004 SDK, which I've just realised, is D3DX supported in it? It contains the d3dx files so I would assume so...[/edit]

[Edited by - Ray2k on August 22, 2005 11:20:42 AM]

Share this post


Link to post
Share on other sites
although some programs are working i still have errors like this:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)
error Code:

#include <stdio.h>
#include <windows.h>
#include <d3dx9.h>

#pragma comment(lib, "d3dx9.lib");
#pragma comment(lib, "d3d9.lib");
#pragma comment(lib, "d3dx.lib");

/******************************************************************************
// For the sake of simplicity, all variables will be globals. I do not
// recommend this in your own code, but since the goal of this article is to
// show how to use texture splatting and nothing else, I opted to take the
// simplest route possible.
//
// Rendering is done through the use of DrawPrimitiveUp, but there should be
// no performance hit because of the small number of vertices involved.
******************************************************************************/


// Window class resources
HWND g_hWnd = NULL;

const UINT MENU_EXIT = 9000;
const UINT MENU_USE_PIXEL_SHADER = 9001;

// Direct3D resources
IDirect3D9* g_Direct3D = NULL;
IDirect3DDevice9* g_Direct3DDevice = NULL;

bool g_CanUsePixelShader = true;
bool g_UsePixelShader = false;
IDirect3DPixelShader9* g_SplatShader = NULL;

// Textures to be blended
IDirect3DTexture9* g_Texture1 = NULL;
IDirect3DTexture9* g_Texture2 = NULL;
IDirect3DTexture9* g_Texture3 = NULL;
IDirect3DTexture9* g_Texture4 = NULL;

// Alphamaps for the fixed function pipeline
IDirect3DTexture9* g_Alphamap1 = NULL;
IDirect3DTexture9* g_Alphamap2 = NULL;
IDirect3DTexture9* g_Alphamap3 = NULL;
IDirect3DTexture9* g_Alphamap4 = NULL;

// Alphamaps for the pixel shaders
IDirect3DTexture9* g_CombinedAlphamap = NULL;

// Interfaces to output text to the screen
ID3DXFont* g_Font = NULL;
ID3DXSprite* g_FontSprite = NULL;

// Variables for the frames per second counter
DWORD g_LastTime;
int g_Frames = 0;
int g_FramesPerSecond = 0;

// Vertex structure and quad
struct QuadVertex {
float x, y, z; // Position
float u1, v1; // Alphamap coordinates
float u2, v2; // Texture coordinates
};

const DWORD VertexFVF = D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEX2;
QuadVertex g_Vertices[] = {
{ -1, 0, -1, 0, 1, 0, 1 },
{ -1, 0, 1, 0, 0, 0, 0 },
{ 1, 0, -1, 1, 1, 1, 1 },
{ 1, 0, 1, 1, 0, 1, 0 },
};

//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
void InitializeWindow(HINSTANCE);
void AddMenu();
bool InitializeDirect3D();
void SetDefaultStates();
bool LoadTextures();
bool LoadAlphamaps();
void CreatePixelShaders();
void CreateFont();
void Render();
void RenderWithShader();
void RenderWithoutShader();
void RenderText();
void CleanUp();
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

//-----------------------------------------------------------------------------
// Generic entry point
//-----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
// Initialization
InitializeWindow(hInstance);
AddMenu();

if(!InitializeDirect3D()) {
CleanUp();
return 1;
}

ShowWindow(g_hWnd, SW_SHOW);

if(!LoadTextures() || !LoadAlphamaps()) {
CleanUp();
return 1;
}

CreatePixelShaders();
CreateFont();
SetDefaultStates();

// g_LastTime = timeGetTime();

// Message pump
MSG msg;
while(true) {
while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if(!GetMessage(&msg, NULL, 0, 0)) {
CleanUp();
return 0;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}

Render();
++g_Frames;

// if(timeGetTime() - g_LastTime >= 1000) {
// g_LastTime += 1000;
// g_FramesPerSecond = g_Frames;
// g_Frames = 0;
// }

Sleep(0);
}
}

//-----------------------------------------------------------------------------
// Generic window creation
//-----------------------------------------------------------------------------
void InitializeWindow(HINSTANCE hInstance) {
// Create and register the window class
WNDCLASSEX wndclass;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);

wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "TextureSplatting";
wndclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

RegisterClassEx(&wndclass);

// Create the actual window, force a client size of 640x480 for simplicity
RECT clientRect;
clientRect.left = 0;
clientRect.top = 0;
clientRect.right = 640;
clientRect.bottom = 480;
AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW ^ WS_MAXIMIZEBOX ^ WS_THICKFRAME, TRUE);

g_hWnd = CreateWindow("TextureSplatting", "Texture Splatting",
WS_OVERLAPPEDWINDOW ^ WS_MAXIMIZEBOX ^ WS_THICKFRAME, CW_USEDEFAULT, CW_USEDEFAULT,
clientRect.right - clientRect.left, clientRect.bottom - clientRect.top,
NULL, NULL, GetModuleHandle(NULL), NULL);
}

//-----------------------------------------------------------------------------
// Add the menu to the window
//-----------------------------------------------------------------------------
void AddMenu() {
HMENU hMenu = CreateMenu();

HMENU hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, MENU_EXIT,"&Exit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&File");

hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING | MF_UNCHECKED, MENU_USE_PIXEL_SHADER, "Use &Pixel Shader");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&View");

SetMenu(g_hWnd, hMenu);
}

//-----------------------------------------------------------------------------
// Generic Direct3D initialization
//-----------------------------------------------------------------------------
bool InitializeDirect3D() {
g_Direct3D = Direct3DCreate9(D3D_SDK_VERSION);
if(g_Direct3D == NULL) {
MessageBox(NULL, "Direct3DCreate9 failed", "Error", MB_OK);
return false;
}

D3DPRESENT_PARAMETERS d3dpp;
memset(&d3dpp, 0, sizeof(D3DPRESENT_PARAMETERS));

D3DDISPLAYMODE d3ddm;
if(FAILED(g_Direct3D->GetAdapterDisplayMode(0, &d3ddm))) {
MessageBox(NULL, "GetAdapterDisplayMode failed", "Error", MB_OK);
return false;
}

d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.hDeviceWindow = g_hWnd;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = TRUE;

if(FAILED(g_Direct3D->CreateDevice(0, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_Direct3DDevice)))
if(FAILED(g_Direct3D->CreateDevice(0, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_Direct3DDevice)))
MessageBox(NULL, "CreateDevice failed", "Error", MB_OK);

return true;
}

//-----------------------------------------------------------------------------
// Set the render and sampler states and the three matrices
//-----------------------------------------------------------------------------
void SetDefaultStates() {
g_Direct3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_Direct3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);

// Allow multiple passes to blend together correctly
g_Direct3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
g_Direct3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_Direct3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

g_Direct3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
// Prevent some ugliness with the alphamaps
g_Direct3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
g_Direct3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

g_Direct3DDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

g_Direct3DDevice->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

g_Direct3DDevice->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

g_Direct3DDevice->SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
g_Direct3DDevice->SetSamplerState(4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

// Set up the matrices
D3DXMATRIX projection, world, view;

D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI / 4.0f, 640.0f / 480.0f, 1.0f, 10.0f);
g_Direct3DDevice->SetTransform(D3DTS_PROJECTION, &projection);

D3DXMatrixIdentity(&world);
g_Direct3DDevice->SetTransform(D3DTS_WORLD, &world);

D3DXVECTOR3 position(0, 2.5f, -.001f);
D3DXVECTOR3 lookat(0, 0, 0);
D3DXVECTOR3 up(0, 1, 0);
D3DXMatrixLookAtLH(&view, &position, &lookat, &up);
g_Direct3DDevice->SetTransform(D3DTS_VIEW, &view);
}

//-----------------------------------------------------------------------------
// Load the terrain textures
//-----------------------------------------------------------------------------
bool LoadTextures() {
if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "texture1.png", &g_Texture1))) {
MessageBox(NULL, "Failed to load 'texture1.png'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "texture2.png", &g_Texture2))) {
MessageBox(NULL, "Failed to load 'texture2.png'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "texture3.png", &g_Texture3))) {
MessageBox(NULL, "Failed to load 'texture3.png'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "texture4.png", &g_Texture4))) {
MessageBox(NULL, "Failed to load 'texture4.png'", "Error", MB_OK);
return false;
}

return true;
}

//-----------------------------------------------------------------------------
// Load the alphamaps
//-----------------------------------------------------------------------------
bool LoadAlphamaps() {
if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "alphamap1.tga", &g_Alphamap1))) {
MessageBox(NULL, "Failed to load 'alphamap1.tga'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "alphamap2.tga", &g_Alphamap2))) {
MessageBox(NULL, "Failed to load 'alphamap2.tga'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "alphamap3.tga", &g_Alphamap3))) {
MessageBox(NULL, "Failed to load 'alphamap3.tga'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "alphamap4.tga", &g_Alphamap4))) {
MessageBox(NULL, "Failed to load 'alphamap4.tga'", "Error", MB_OK);
return false;
}

if(FAILED(D3DXCreateTextureFromFile(g_Direct3DDevice, "combinedalphamap.tga", &g_CombinedAlphamap))) {
MessageBox(NULL, "Failed to load 'combinedalphamap.tga'", "Error", MB_OK);
return false;
}

return true;
}

//-----------------------------------------------------------------------------
// Create the pixel shaders if the device supports PS 1.4
//-----------------------------------------------------------------------------
void CreatePixelShaders() {
D3DCAPS9 caps;

g_Direct3DDevice->GetDeviceCaps(&caps);

if(caps.PixelShaderVersion >= D3DPS_VERSION(1, 4)) {
ID3DXBuffer* pShader = NULL;

if(FAILED(D3DXAssembleShaderFromFile("splatshader.psh", NULL, NULL, 0, &pShader, NULL))) {
MessageBox(NULL, "D3DXAssembleShaderFromFile failed", "Error", MB_OK);
g_CanUsePixelShader = false;
EnableMenuItem(GetMenu(g_hWnd), MENU_USE_PIXEL_SHADER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
if(pShader != NULL) pShader->Release();
return;
}

g_Direct3DDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &g_SplatShader);
pShader->Release();
}
else {
MessageBox(NULL, "Your video card does not support Pixel Shader 1.4.\nYou will only be able to view this example through the Fixed Function Pipeline.", "Warning", MB_OK);
g_CanUsePixelShader = false;
EnableMenuItem(GetMenu(g_hWnd), MENU_USE_PIXEL_SHADER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
}
}

//-----------------------------------------------------------------------------
// Create the font used to render text
//-----------------------------------------------------------------------------
void CreateFont() {
/*
HDC hDC = GetDC(NULL);
int height = 14 * (GetDeviceCaps(hDC, LOGPIXELSY) / 72);
ReleaseDC(NULL, hDC);

if(FAILED(D3DXCreateSprite(g_Direct3DDevice, &g_FontSprite))) {
MessageBox(NULL, "D3DXCreateSprite failed", "Warning", MB_OK);
return;
}

if(FAILED(D3DXCreateFont(g_Direct3DDevice, height, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &g_Font))) {
MessageBox(NULL, "D3DXCreateFont failed", "Warning", MB_OK);
}
*/

}

//-----------------------------------------------------------------------------
// Render the texture splatted quad and text
//-----------------------------------------------------------------------------
void Render() {
g_Direct3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
g_Direct3DDevice->BeginScene();

g_Direct3DDevice->SetFVF(VertexFVF);

if(g_UsePixelShader)
RenderWithShader();
else
RenderWithoutShader();

RenderText();

g_Direct3DDevice->EndScene();
g_Direct3DDevice->Present(NULL, NULL, NULL, NULL);
}

//-----------------------------------------------------------------------------
// Render using the pixel shader
//-----------------------------------------------------------------------------
void RenderWithShader() {
// There are no render states to worry about

g_Direct3DDevice->SetPixelShader(g_SplatShader);

g_Direct3DDevice->SetTexture(0, g_CombinedAlphamap);
g_Direct3DDevice->SetTexture(1, g_Texture1);
g_Direct3DDevice->SetTexture(2, g_Texture2);
g_Direct3DDevice->SetTexture(3, g_Texture3);
g_Direct3DDevice->SetTexture(4, g_Texture4);

g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));
}

//-----------------------------------------------------------------------------
// Render using the fixed function pipeline
//-----------------------------------------------------------------------------
void RenderWithoutShader() {
// Alphamap: take the alpha from the alphamap, we don't care about the color
g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_Direct3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

// Texture: take the color from the texture, take the alpha from the previous stage
g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
g_Direct3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_Direct3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

// Disable textures from the pixel shader mode
g_Direct3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
g_Direct3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

// Disable the pixel shader
g_Direct3DDevice->SetPixelShader(NULL);

g_Direct3DDevice->SetTexture(0, g_Alphamap1);
g_Direct3DDevice->SetTexture(1, g_Texture1);
g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

g_Direct3DDevice->SetTexture(0, g_Alphamap2);
g_Direct3DDevice->SetTexture(1, g_Texture2);
g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

g_Direct3DDevice->SetTexture(0, g_Alphamap3);
g_Direct3DDevice->SetTexture(1, g_Texture3);
g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));

g_Direct3DDevice->SetTexture(0, g_Alphamap4);
g_Direct3DDevice->SetTexture(1, g_Texture4);
g_Direct3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Vertices, sizeof(QuadVertex));
}


//-----------------------------------------------------------------------------
// Render the status information on the screen
//-----------------------------------------------------------------------------
void RenderText() {
/*
if(g_Font) {
RECT textLocation;
textLocation.top = textLocation.left = 4;
textLocation.bottom = 476;
textLocation.right = 636;

char fpsText[40];
sprintf(fpsText, "Frames Per Second: %d", g_FramesPerSecond);

g_FontSprite->Begin(D3DXSPRITE_SORT_TEXTURE);

g_Font->DrawText(g_FontSprite, fpsText, -1, &textLocation, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(255, 255, 255));

textLocation.top = 18;
if(g_UsePixelShader)
g_Font->DrawText(g_FontSprite, "Pixel Shader Enabled", -1, &textLocation, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(255, 255, 255));
else
g_Font->DrawText(g_FontSprite, "Fixed Function Pipeline Enabled", -1, &textLocation, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(255, 255, 255));

textLocation.top = 32;

g_FontSprite->End();
}
*/

}

//-----------------------------------------------------------------------------
// Release allocated resources
//-----------------------------------------------------------------------------
void CleanUp() {
if(g_Texture1 != NULL) g_Texture1->Release();
if(g_Texture2 != NULL) g_Texture2->Release();
if(g_Texture3 != NULL) g_Texture3->Release();
if(g_Texture4 != NULL) g_Texture4->Release();
if(g_Alphamap1 != NULL) g_Alphamap1->Release();
if(g_Alphamap2 != NULL) g_Alphamap2->Release();
if(g_Alphamap3 != NULL) g_Alphamap3->Release();
if(g_Alphamap4 != NULL) g_Alphamap4->Release();
// if(g_combinedalphamap != NULL) g_CombinedAlphamap->Release();
if(g_Font != NULL) g_Font->Release();
if(g_FontSprite != NULL) g_FontSprite->Release();
if(g_SplatShader != NULL) g_SplatShader->Release();
if(g_Direct3DDevice != NULL) g_Direct3DDevice->Release();
if(g_Direct3D != NULL) g_Direct3D->Release();
}

//-----------------------------------------------------------------------------
// Window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_COMMAND:
switch(LOWORD(wParam)) {
case MENU_EXIT:
PostQuitMessage(0);
break;

case MENU_USE_PIXEL_SHADER:
if(g_UsePixelShader) {
g_UsePixelShader = false;
CheckMenuItem(GetMenu(g_hWnd), MENU_USE_PIXEL_SHADER, MF_BYCOMMAND | MF_UNCHECKED);
}
else {
g_UsePixelShader = true;
CheckMenuItem(GetMenu(g_hWnd), MENU_USE_PIXEL_SHADER, MF_BYCOMMAND | MF_CHECKED);
}
break;
}
break;

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

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





What do you all sugest Reinstall my windows or someting else?

Share this post


Link to post
Share on other sites
Quote:
Original post by Raxvan
although some programs are working i still have errors like this:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals

When you created the project you created it as a Console app. Console apps expect a main function. Win32 applications use WinMain. Recreate the project as a Win32 project and all should be fine.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ray2k
My includes are as follows:
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <mmsystem.h>
#include <ddraw.h>
#include <fcntl.h>
#include <signal.h>
#include <float.h>
#include <io.h>
#include <d3d9.h>
#include <d3dx9.h>


Don't include ddraw.h, D3D9 and DDraw are not compatible. You don't need to include d3d9.h, it's included by d3dx9.h.

Share this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
I think it's specific to Visual Studio, that is it won't work on other compilers and isn't a "standard" part of C++ (although the #pragma command itself is, IIRC). I have seen it in tutorials before though, DrunkenHyena used this.

EDIT: Actually, that's probably a stupid possible reason. Maybe you were just looking at a medicore tutorial? Most DirectX tutorials consider the possibility that you're using Visual Studio.


The offical tutorials and samples add the libraries in the project settings. I use the "pragma comment" method because it's more obvious and easy to explain. You don't have to dig around in all the tabs just to see what's included. Also, I find a long line of libraries in a single edit box to be absolutely horrible. Functionally the 2 methods are identical though, so use the method you prefer.

Share this post


Link to post
Share on other sites
tnx now the problem is solved for the moment
the problem was that i created the cpp file without a project and when i compiled the vc++ automatically created a console project :( next time i will be more careful

Share this post


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