How to optimize code

Started by
5 comments, last by Oberon_Command 6 years ago

I am using this code for render:

d3d = Direct3DCreate9(D3D_SDK_VERSION);

 D3DPRESENT_PARAMETERS d3dpp;
 ZeroMemory(&d3dpp, sizeof(d3dpp));
 d3dpp.Windowed = TRUE;
 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
 d3dpp.hDeviceWindow = hwnd;
 d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;

Drop fps

How to optimize code this code?)

2)How to make transparent window(CreateWindowEx) not using aero(SetLayeredWindowAttributes)?

Thank you in advance

 

Advertisement

First off, why are you using D3D9?  D3D10 is like 12 years old now, I would recommend D3D11 if your OS supports it.  There is really not much knowledge that will transfer over to newer, modern, APIs so it's really kinda pointless to learn at this point in time.

Secondly there is no way to really optimize that code, it should be run once (outside of certain situations).

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

On 4/7/2018 at 10:45 AM, Ads34 said:

How to make transparent window(CreateWindowEx) not using aero(SetLayeredWindowAttributes)?

If you are talking about the window as a whole, mark the window as a layered-style window and set the layer's alpha values:


SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); 
SetLayeredWindowAttributes(hWnd, 0, targetOpacity, LWA_ALPHA);

 

1 hour ago, frob said:

If you are talking about the window as a whole, mark the window as a layered-style window and set the layer's alpha values:



SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); 
SetLayeredWindowAttributes(hWnd, 0, targetOpacity, LWA_ALPHA);

 

Do not you use SetLayeredWindowAttributes to do this?

On 4/7/2018 at 8:45 AM, Ads34 said:

D3DPRESENT_PARAMETERS d3dpp;
 ZeroMemory(&d3dpp, sizeof(d3dpp));

 

On 4/7/2018 at 8:45 AM, Ads34 said:

How to optimize code this code?)

#1: D3DPRESENT_PARAMETERS d3dpp = { 0 };

#2: Switch to Direct3D 11 or Direct3D 12.

#3: Why exactly did you point at this to optimize?  It should be run once and forgotten.  Are you running this every frame?  Is a profiler showing you that this needs to be optimized?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

8 minutes ago, L. Spiro said:

#2: Switch to Direct3D 11 or Direct3D 12.

I'm going to take a wild guess and suggest that OP is running Windows XP.

Is that correct? @Ads34

This topic is closed to new replies.

Advertisement