Sign in to follow this  
falcon93

Sprites and D3D9

Recommended Posts

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:

[quote name="Visual Studio Message"]
Unhandled exception at 0x0fd49c2d in AvoidBall.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
[/quote]



The "green arrow" stops on the 19:th line:
[quote name="Line 19"]
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
[/quote]



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!

Share this post


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

[color="#1C2837"][size="2"]D3D Debug runtimes? How do I use it?[/size][/color]

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313782893' post='4851352']
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?
[/quote]

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.

[quote name='falcon93' timestamp='1313782893' post='4851352']
[color="#1C2837"][size="2"]D3D Debug runtimes? How do I use it?[/size][/color]
[/quote]

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.

Share this post


Link to post
Share on other sites
[color=#1C2837][size=2][quote]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.[/quote][/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]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 :/[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[color=#1C2837][size=2]
[/size][/color]

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313784428' post='4851360']
[color="#1C2837"][size="2"][quote]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.[/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]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 :/[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"] [/color]
[/quote]

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.

Share this post


Link to post
Share on other sites
Thank you very much, I've learned something new :D

The question now is how I should use this number?

[quote name="HRESULT"]
-858993460
[/quote]


The DirectX Error Lookup tool does only provide this:
[quote name="DirectX Error Lookup Tool"]

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


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

Share this post


Link to post
Share on other sites
try running this code.
[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 );
[/code]

maybve it is a Win32 Error.

also check if the interfaces are NULL or nullpre( C++0x )
what about the debug runtimes ?

Share this post


Link to post
Share on other sites
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
[img]http://i54.tinypic.com/hw0qcy.jpg[/img]



@Aerodactyl55:[size="2"][color="#1c2837"] I'm calling it?[/color][/size]
[size="2"][color="#1c2837"][code]
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);
}[/code]
[/color][/size]

Thank you btoh for helping me appreciated :)

Share this post


Link to post
Share on other sites
[size="2"][color="#1c2837"][code]
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);
}
[/code]
[/color][/size]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).

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313841932' post='4851569']
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?
[/quote]

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

[code]
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;
}
[/code]

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.

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313835548' post='4851542']
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
[img]http://i54.tinypic.com/hw0qcy.jpg[/img]



@Aerodactyl55:[size="2"][color="#1c2837"] I'm calling it?[/color][/size]
[size="2"][color="#1c2837"][code]
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);
}[/code]
[/color][/size]

Thank you btoh for helping me appreciated :)
[/quote]

you need to select the "Use The Debug Version Of Direct3D 9"

Share this post


Link to post
Share on other sites
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 [i]you[/i] 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! :)

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313862843' post='4851674']
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?
[/quote]

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.

[quote name='falcon93' timestamp='1313862843' post='4851674']
2. What do [i]you[/i] think is better? Using Sprites or setting up vertices?
[/quote]

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.

[quote name='falcon93' timestamp='1313862843' post='4851674']
@ryan20fun: Ok, I've checked the Debug Runtime Version. Should I do anything with the Debug Output Level?
[/quote]

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.

[quote name='falcon93' timestamp='1313862843' post='4851674']
Where will I find this debug help in Visual Studio when I work?
[/quote]

D3D will output the info to the "Output" Window, the one that tells you X has been compiled.

Share this post


Link to post
Share on other sites
[quote]
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?
[/quote]
Try using D3DXCreateTextureFromFileEx() instead of the D3DXCreateTextureFromFile().

Share this post


Link to post
Share on other sites
[quote name='Aerodactyl55' timestamp='1313869180' post='4851701']
[quote]
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?
[/quote]
Try using D3DXCreateTextureFromFileEx() instead of the D3DXCreateTextureFromFile().
[/quote]

:D missed that, +1

Share this post


Link to post
Share on other sites
My stationary computer supports D3DX_DEFAULT_NONPOW2, but my laptop does not [img]http://public.gamedev.net/public/style_emoticons/default/sad.gif[/img]
Is there any way (that is supported on all computers) to draw an image with it's original proportions?

I'm trying to find a solid solution that will support three things:
1. png images with transparent parts
2. sprite sheet animation
3. rotation
(and of course original proportions)

Based on this, which way should I choose? There has to be something that support this 3 things, or?

Thanks everyone for helping :)

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313871715' post='4851717']
1. png images with transparent parts
[/quote]

you can use whatever format you want, because with the D3DXCreateTextureFromFileEx can take a colour key IE use this colour for alpha.

[quote name='falcon93' timestamp='1313871715' post='4851717']
2. sprite sheet animation
3. rotation
[/quote]
[url="http://www.codesampler.com/dx9src/dx9src_8.htm#dx9_d3dxsprite"]
here[/url] is the origanal example and the rotation i got from a "the toy maler" tutorial

so here is the load code
[code]
D3DXIMAGE_INFO d3dxImageInfo;

D3DXCreateTextureFromFileEx( D3D9Device,
L"..\\donut.bmp",
320, // I had to set width manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
384, // I had to set height manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
1, // Don't create mip-maps when you plan on using D3DXSPRITE. It throws off the pixel math for sprite animation.
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.0f, 1.0f),// now black will be transparent
&d3dxImageInfo,
NULL,
&texture );

[/code]

and here is the rendering code
[code]
D3DXMATRIX matRotate;
D3DXVECTOR2 center(framesizex / 2, framesizey / 2);
D3DXVECTOR2 position(posx - framesizex / 2, posy - framesizey / 2);
D3DXMatrixTransformation2D(&matRotate, NULL, NULL, NULL, &center, rotation, &position);

id3dxsprite->SetTransform(&matRotate);

id3dxsprite->Draw(texture, &srcRect, NULL, NULL, tint);
D3DXMatrixRotationZ(&matRotate, 0);
id3dxsprite->SetTransform(&matRotate);
[/code]

now id3dxsprite is a ID3DXSPRITE interface.
posx is the X position and posy is the Y position
framesizex is the horizontal size of the animation and framesizey is the horizontal.

the example code + the rendering code should get the job done.
if you want ill upload the class that i use.
:) :) :)

Share this post


Link to post
Share on other sites
[quote name='falcon93' timestamp='1313874852' post='4851728']
I'll take a look at the code, thank you :) Meanwhile, what about keeping the images original proportions? I tried to set the width and height manually in my code, but it still rounds?
[/quote]

hmm, thats interesting.

are you using the card that supported non power of two ?
also i read that surfaces dont have that limit, and i think there was a get texture or something like that method that a surface has.
so you could use that instead.

can you past the code you are using ?
if it is the same as the example, then the card must not support non pwer of two textures, but for verification can you upload your app so i can run it and see if it does the same on my side ?
if you do, can you just say what version of DX and c++ your using as well

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