Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sprites and D3D9


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
31 replies to this topic

#1 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2011 - 01:06 PM

Hi!

I been trying to solve this by my own, but it simply don't make any sence. I'm trying to do the required initializing of the necessary D3DX components, so I can use the Sprite interface and draw an image. The main code runs fine, but as soon as the loop reaches the Graphics class, it crashes. Here's my code:

Graphics.cpp
[source lang="cpp"]#include "Graphics.h"Graphics::Graphics(HWND hWnd){ d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = 1280; d3dpp.BackBufferHeight = 800; D3DXCreateSprite(d3ddev, &sprite); d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);}Graphics::~Graphics(void){}// --------------------------------------------------------------------------------// Name: Begin// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::Begin(void){ sprite->Begin(D3DXSPRITE_ALPHABLEND);}// --------------------------------------------------------------------------------// Name: Draw// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::Draw(void){}// --------------------------------------------------------------------------------// Name: End// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::End(void){ sprite->End();}[/source]

Graphics.h
[source lang="cpp"]#pragma once#include <d3d9.h>#include <d3dx9.h>#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")class Graphics{public: Graphics(HWND hWnd); ~Graphics(void); // -------------------------------------------------------------------------------- // Name: Begin // Desc: // Rtrn: None // -------------------------------------------------------------------------------- void Begin(void); // -------------------------------------------------------------------------------- // Name: Draw // Desc: // Rtrn: None // -------------------------------------------------------------------------------- void Draw(void); // -------------------------------------------------------------------------------- // Name: End // Desc: // Rtrn: None // -------------------------------------------------------------------------------- void End(void);private: LPDIRECT3D9 d3d; D3DPRESENT_PARAMETERS d3dpp; LPDIRECT3DDEVICE9 d3ddev; LPD3DXSPRITE sprite;};[/source]


Nothing is null here, right? Still I get this error on crash:

Unhandled exception at 0x0fd49c2d in AvoidBall.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.




The "green arrow" stops on the 19:th line:

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




What am I doing wrong? I know that I've asked alot about this basic graphics code, but it simply won't work for me :( Please help!

Sponsor:

#2 ryan20fun   Members   -  Reputation: 680

Like
0Likes
Like

Posted 19 August 2011 - 01:23 PM

can you get the result of thos D3D creation calls ?
because checking the return values of D3D is very important, and dont forget to try the D3D Debug runtimes.
they help a lot.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#3 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2011 - 01:41 PM

I know how to get the HRESULT from the method, but how do I check the actual info of the HRESULT? I can't write the HRESULT in a messagebox? Is there any smarter way then checking with a switch?

D3D Debug runtimes? How do I use it?

#4 ryan20fun   Members   -  Reputation: 680

Like
0Likes
Like

Posted 19 August 2011 - 01:51 PM

I know how to get the HRESULT from the method, but how do I check the actual info of the HRESULT? I can't write the HRESULT in a messagebox? Is there any smarter way then checking with a switch?


it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.

D3D Debug runtimes? How do I use it?


goto the Microsoft DirectX SDK folder in the StartMenu -> then in the
startmenu -> Microsoft DirectX SDK( whatever version your using ) -> DirectX Utilities -> DirectX Control Panel.
then set the debug out put and select "use debug runtimes" option.
then run your game again and check the "output window" of the IDE for the info from D3D.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#5 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2011 - 02:07 PM

it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.




Sorry, but, how do I set a break point? And how can I copy the value of the HRESULT? Sorry, but I've never done this before, first time I even hear about it :/





#6 ryan20fun   Members   -  Reputation: 680

Like
1Likes
Like

Posted 19 August 2011 - 02:11 PM

it would be quicker to set a break point and copy the value of the HRESULT and look it up in the DirectX Error Lookup tool / google.



Sorry, but, how do I set a break point? And how can I copy the value of the HRESULT? Sorry, but I've never done this before, first time I even hear about it :/



to set a break point( in VS ) click in the light brown line on the left of the code page, or there should be a add break point here button
when the break point hits, hold the mouse over the hresult and a little box should pop up, select the text in there and copy it.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#7 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 19 August 2011 - 02:37 PM

Thank you very much, I've learned something new :D

The question now is how I should use this number?

-858993460



The DirectX Error Lookup tool does only provide this:

HRESULT: 0xa766cb98 (2808531864)
Name: Unknown
Description: n/a
Severity code: Failed
Facility Code: Unknown (1894)
Error Code: 0xcb98 (52120)



Putting this number into google won't give any good results. What should I do with it?



#8 ryan20fun   Members   -  Reputation: 680

Like
0Likes
Like

Posted 19 August 2011 - 11:27 PM

try running this code.
TDWORD error = GetLastError();
			LPTSTR errorText = NULL;

			FormatMessage(
				// use system message tables to retrieve error text
				FORMAT_MESSAGE_FROM_SYSTEM
				// allocate buffer on local heap for error text
				|FORMAT_MESSAGE_ALLOCATE_BUFFER
				// Important! will fail otherwise, since we're not 
				// (and CANNOT) pass insertion parameters
				|FORMAT_MESSAGE_IGNORE_INSERTS,  
				NULL,					// unused with FORMAT_MESSAGE_FROM_SYSTEM
				error,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR)&errorText,		// output 
				0,						// minimum size for output buffer
				NULL);					// arguments - see note 

			wstring ws( errorText );
			string errorstring( ws.begin(), ws.end() );

			MessageBoxA( NULL, errorstring.c_str(), "Error", MB_OK );

maybve it is a Win32 Error.

also check if the interfaces are NULL or nullpre( C++0x )
what about the debug runtimes ?
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#9 Aerodactyl55   Members   -  Reputation: 149

Like
1Likes
Like

Posted 20 August 2011 - 03:21 AM

You must create the sprite before using it. During Initialization call the D3DXCreateSprite() function after creating the device.

#10 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 20 August 2011 - 04:19 AM

What header do I have to include to use TDWORD and wstring? Also, I've checked for null values with if statements but didin't find any.

Regarding the Debug Runtimes. This is the window, but now I don't know what to change? Your path worked untill this window :P
Posted Image



@Aerodactyl55: I'm calling it?
Graphics::Graphics(HWND hWnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	d3dpp.Windowed   = true;
	d3dpp.SwapEffect  = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow  = hWnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = 1280;
	d3dpp.BackBufferHeight = 800;

	D3DXCreateSprite(d3ddev, &sprite);

	HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}


Thank you btoh for helping me appreciated :)

#11 Chargh   Members   -  Reputation: 110

Like
1Likes
Like

Posted 20 August 2011 - 04:52 AM

Graphics::Graphics(HWND hWnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	d3dpp.Windowed   = true;
	d3dpp.SwapEffect  = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow  = hWnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = 1280;
	d3dpp.BackBufferHeight = 800;

	D3DXCreateSprite(d3ddev, &sprite);

	HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}
You call D3DXCreateSprite with d3ddev as a parameter. Then in the line following it you create d2ddev, since this is your constructor and I don't see you setting d3ddev to NULL it would be logical to assume that they crash happens in D3DXCreateSprite since you pass it a invalid pointer (unless you are using VS in debug mode which I think sets all uninitialized variables to 0). Also you should error check these functions (d3d != NULL, d3d->CreateDevice(...) != S_OK).

#12 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 20 August 2011 - 05:10 AM

Oh, thanks, it worked at and made sence too :) Thanks. I'll add error checking to, there's however a small problem more:

So, it builds fine, but the texture I try to draw on the screen isn't showing? Graphics.cpp code below:

[source lang="cpp"]#include "Graphics.h"Graphics::Graphics(HWND hWnd){ d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = 1280; d3dpp.BackBufferHeight = 800; HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateSprite(d3ddev, &sprite); D3DXCreateTextureFromFile(d3ddev, L"texture.jpg", &texture); position.x = 100; position.y = 100; position.z = 0;}Graphics::~Graphics(void){}// --------------------------------------------------------------------------------// Name: Begin// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::Begin(void){ sprite->Begin(D3DXSPRITE_ALPHABLEND);}// --------------------------------------------------------------------------------// Name: Draw// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::Draw(void){ sprite->Draw(texture, NULL, NULL, &position, 0xFFFFFFFF);}// --------------------------------------------------------------------------------// Name: End// Desc: // Rtrn: None// --------------------------------------------------------------------------------void Graphics::End(void){ sprite->End();}[/source]

#13 Chargh   Members   -  Reputation: 110

Like
1Likes
Like

Posted 20 August 2011 - 05:42 AM

It has been ages since I last looked at D3D9 but I think that you should check out the following.
1. Error check texture loading, make sure its loaded!
2. I don't know to what extend d3dxsprite sets its own rendering states (try searching the help files that come with the sdk) but you might want to try to turn of lighting (again its in the help files).
3. I don't see any d3ddev->Clear(...), d3ddev->BeginScene() d3ddev->EndScene() and d3ddev->Present(...). Do you call them somewhere else?

Maybe its a good idea to check out the tutorials in the help files, make your application mimic the the one that only draws a triangle and remove the triangle code and insert sprite begin, draw, end.

#14 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 20 August 2011 - 06:05 AM

Do I have to use the clear, beginscene, endscene and present even with Sprite?

I started off by fixing the Clear method and choosing it to clear with black, but it gives me strange results. In fullscreen my application background is black, but when I run it windowed it is white? And I notice it gets really laggy when I run Clear?

#15 Chargh   Members   -  Reputation: 110

Like
1Likes
Like

Posted 20 August 2011 - 06:14 AM

Do I have to use the clear, beginscene, endscene and present even with Sprite?

I started off by fixing the Clear method and choosing it to clear with black, but it gives me strange results. In fullscreen my application background is black, but when I run it windowed it is white? And I notice it gets really laggy when I run Clear?


Yes they are essential. You should try to structure your program like this:

int WINAPI WinMain(...)
{
 //create your window
 ...
 
 //create graphics
 Graphics g(hwnd);
 //create a way to check if this was successful or better move the initialization into a separate method
 if (!g.init(hwnd))
 {
   //FAIL, I can't stress it enough if you are serious about finding the problem you have to rule out bogus function calls with error checking
 }

  //maybe a separate method to load the texture(s)?
 
 //your game loop
 while (gameNotClosed)
 {
  //update window
  
  //begin the scene
  g.beginScene(); //which calls d3ddev->Clear d3ddev->BeginScene()
 
   //draw sprite
   g.begin(); //which calls sprite->begin(), and try turning of alpha blending for the moment
   g.draw(); //which calls the drawing function on the sprite
   g.end(); //which calls sprite->end();
  
  //EDIT: and ofcourse EndScene()
  g.endScene();
 } 

 return 0;
}

And ofcourse do not use the standard updatewindow function to acquire window messages, try searching the forums for "game loop" I think on windows you should use PeekMessage to acquire the messages but I haven't been on a windows platform for a while so I can't say for sure.

#16 Aerodactyl55   Members   -  Reputation: 149

Like
0Likes
Like

Posted 20 August 2011 - 07:27 AM

Are you clearing the Z-Buffer? If you are clearing the z-buffer when you didn't create one you may run into some artifacts/problems! The sprite Draw(), Begin() and End() methods must be called between BeginScene() and EndScene() pair.

#17 ryan20fun   Members   -  Reputation: 680

Like
1Likes
Like

Posted 20 August 2011 - 08:15 AM

What header do I have to include to use TDWORD and wstring? Also, I've checked for null values with if statements but didin't find any.

Regarding the Debug Runtimes. This is the window, but now I don't know what to change? Your path worked untill this window :P
Posted Image



@Aerodactyl55: I'm calling it?

Graphics::Graphics(HWND hWnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	d3dpp.Windowed   = true;
	d3dpp.SwapEffect  = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow  = hWnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = 1280;
	d3dpp.BackBufferHeight = 800;

	D3DXCreateSprite(d3ddev, &sprite);

	HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}


Thank you btoh for helping me appreciated :)


you need to select the "Use The Debug Version Of Direct3D 9"
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#18 falcon93   Members   -  Reputation: 121

Like
0Likes
Like

Posted 20 August 2011 - 11:54 AM

Ok, I solved it by simply add the BeginScene, EndScene and Present methods. Everything works well now, my current code is below (some of the code in main.cpp is just temporary)



Main.cpp
[source lang="cpp"]#include <Windows.h>#include "Main.h"#include "Graphics.h"#include "Input.h"Graphics* graphics;Input* input;LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.hInstance = hInstance; wc.lpfnWndProc = WindowProc; wc.lpszClassName = L"AvoidBallClass"; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClassEx(&wc); HWND hWnd; hWnd = CreateWindowEx(NULL, L"AvoidBallClass", L"AvoidBall", WS_OVERLAPPED, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); MSG msg; graphics = new Graphics(hWnd); input = new Input(); // Temporary LPDIRECT3DTEXTURE9 texture; texture = graphics->LoadTexture(L"spitfire.png"); D3DXVECTOR3 pos; pos.x = 0; pos.y = 0; pos.z = 0; RECT rectangle; rectangle.bottom = 400; rectangle.top = 0; rectangle.right = 100; rectangle.left = 0; while (true) { while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } graphics->Begin(); graphics->Draw(texture, pos, 0); graphics->End(); if (input->ButtonDownOnce(VK_ESCAPE)) { PostQuitMessage(0); return 0; } } // TODO: Clean up resources. return msg.wParam;}[/source]



Graphics.cpp
[source lang="cpp"]#include "Graphics.h"Graphics::Graphics(HWND hWnd){ d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hWnd; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferWidth = 1280; d3dpp.BackBufferHeight = 800; d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateSprite(d3ddev, &sprite);}Graphics::~Graphics(void){}// --------------------------------------------------------------------------------// Name: Begin// Desc: Prepares a device for drawing// Rtrn: None// --------------------------------------------------------------------------------void Graphics::Begin(void){ d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1, 0); d3ddev->BeginScene(); sprite->Begin(D3DXSPRITE_ALPHABLEND);}// --------------------------------------------------------------------------------// Name: Draw// Desc: Draws a texture to the screen// Rtrn: None// --------------------------------------------------------------------------------void Graphics::Draw(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, int alpha){ color = D3DCOLOR_COLORVALUE(0, 0, 0, alpha); sprite->Draw(texture, NULL, NULL, &position, 0xFFFFFFFF);}// --------------------------------------------------------------------------------// Name: DrawSpriteSheet// Desc: Draws a texture to the screen with enabled source rectangle// Rtrn: None// --------------------------------------------------------------------------------void Graphics::DrawSpriteSheet(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha){ color = D3DCOLOR_COLORVALUE(255, 255, 255, alpha); sprite->Draw(texture, &source_rectangle, NULL, &position, 0xFFFFFFFF);}// --------------------------------------------------------------------------------// Name: DrawEx// Desc: Draws a texture to the screen with enabled rotation// Rtrn: None// --------------------------------------------------------------------------------void Graphics::DrawEx(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha, D3DXVECTOR3 rotation_orgin, float rotation){}// --------------------------------------------------------------------------------// Name: End// Desc: Restores the device state to how it was before Begin was called// Rtrn: None// --------------------------------------------------------------------------------void Graphics::End(void){ sprite->End(); d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL);}// --------------------------------------------------------------------------------// Name: LoadTexture// Desc: Creates a texture from a file// Rtrn: Returns the created texture// --------------------------------------------------------------------------------LPDIRECT3DTEXTURE9 Graphics::LoadTexture(LPCWSTR path){ D3DXCreateTextureFromFile(d3ddev, path, &texture); return texture;}[/source]


Graphics.h
[source lang="cpp"]#pragma once#include <d3d9.h>#include <d3dx9.h>#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")class Graphics{public: Graphics(HWND hWnd); ~Graphics(void); // -------------------------------------------------------------------------------- // Name: Begin // Desc: Prepares a device for drawing // Rtrn: None // -------------------------------------------------------------------------------- void Begin(void); // -------------------------------------------------------------------------------- // Name: Draw // Desc: Draws a texture to the screen // Rtrn: None // -------------------------------------------------------------------------------- void Draw(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, int alpha); // -------------------------------------------------------------------------------- // Name: DrawSpriteSheet // Desc: Draws a texture to the screen with enabled source rectangle // Rtrn: None // -------------------------------------------------------------------------------- void DrawSpriteSheet(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha); // -------------------------------------------------------------------------------- // Name: DrawEx // Desc: Draws a texture to the screen with enabled rotation // Rtrn: None // -------------------------------------------------------------------------------- void DrawEx(LPDIRECT3DTEXTURE9 texture, D3DXVECTOR3 position, RECT source_rectangle, int alpha, D3DXVECTOR3 rotation_orgin, float rotation); // -------------------------------------------------------------------------------- // Name: End // Desc: Restores the device state to how it was before Begin was called // Rtrn: None // -------------------------------------------------------------------------------- void End(void); // -------------------------------------------------------------------------------- // Name: LoadTexture // Desc: Creates a texture from a file // Rtrn: Returns the created texture // -------------------------------------------------------------------------------- LPDIRECT3DTEXTURE9 LoadTexture(LPCWSTR path);private: LPDIRECT3D9 d3d; D3DPRESENT_PARAMETERS d3dpp; LPDIRECT3DDEVICE9 d3ddev; LPD3DXSPRITE sprite; LPDIRECT3DTEXTURE9 texture; D3DCOLOR color;};[/source]

Does this seem correct, or should you have changed anything? (I'll also add the error checking)

Then I also have 2 more questions:

1. I've noticed that the texture is scaling to the closest 64x64, 128x128, 256x256, 512x512, 1024x1024 etc. If my texture is 300 in height, it's going to be scaled to 512 in height. Can I disable this somehow?

2. What do you think is better? Using Sprites or setting up vertices?


@ryan20fun: Ok, I've checked the Debug Runtime Version. Should I do anything with the Debug Output Level? Where will I find this debug help in Visual Studio when I work?


Thanks for helping! :)

#19 ryan20fun   Members   -  Reputation: 680

Like
1Likes
Like

Posted 20 August 2011 - 12:45 PM

1. I've noticed that the texture is scaling to the closest 64x64, 128x128, 256x256, 512x512, 1024x1024 etc. If my texture is 300 in height, it's going to be scaled to 512 in height. Can I disable this somehow?


it depends, does the card support non power of two textures ?
if so you can manually specify the x and y size, its what i do.

2. What do you think is better? Using Sprites or setting up vertices?


i would vote sprites for now, i think if you are going to upgrade to D3D10 / 11, it might be easier to use vertices and rotate them manually etc.
because from D3D10, Microsoft dropped the fixed function pipeline.

@ryan20fun: Ok, I've checked the Debug Runtime Version. Should I do anything with the Debug Output Level?


the more debug out put D3D will Do.
if you select the highest out put, you will get mesages for everything you did wtong, and forgot to do.

Where will I find this debug help in Visual Studio when I work?


D3D will output the info to the "Output" Window, the one that tells you X has been compiled.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

#20 Aerodactyl55   Members   -  Reputation: 149

Like
1Likes
Like

Posted 20 August 2011 - 01:39 PM

1. I've noticed that the texture is scaling to the closest 64x64, 128x128, 256x256, 512x512, 1024x1024 etc. If my texture is 300 in height, it's going to be scaled to 512 in height. Can I disable this somehow?

Try using D3DXCreateTextureFromFileEx() instead of the D3DXCreateTextureFromFile().




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS