Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Erik Rufelt

Member Since 17 Apr 2002
Offline Last Active Yesterday, 06:24 AM

#5239095 [Win32] No WM_KEYDOWN for screenshot-key

Posted by Erik Rufelt on 08 July 2015 - 06:27 PM

This seems to catch the WM_KEYDOWN:

You can also skip CallNextHookEx and just return 1 to skip normal handling of that key if you want to disable the key for WndProc.

HHOOK hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), 0);

...

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
	if(nCode >= 0 && nCode == HC_ACTION) {
		KBDLLHOOKSTRUCT* p = reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam);
		switch(wParam) {
			case WM_KEYDOWN:
				p->vkCode == VK_SNAPSHOT;
			break;
		}
	}

	return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}



#5239037 Simulating the sun

Posted by Erik Rufelt on 08 July 2015 - 12:44 PM

https://en.wikipedia.org/wiki/Position_of_the_Sun

 

If you pick a position on earth and a date and time you can calculate the position. The first part of the article lists equations ending up with rectangular coordinates which I guess is what you want.




#5238916 generic fancy procedural graphics question

Posted by Erik Rufelt on 07 July 2015 - 10:19 PM

Not entirely sure what you mean with plasma, do you have any example screen from another game?

Should it be blended with the background?  Have distortion?  What is your color-format, 32-bit?  Also drawn as triangles?

 

I would try a bunch of white triangles (or circles if the plasma supposed to be smooth) in random positions and sizes covering the area where you want the plasma, with some alpha transparency and additive blending.

So like for(each pixel inside plasma) backBuffer[i] += RGB(50, 50, 50) or similar...




#5238288 How to correctly convert A8R8G8B8 texture?

Posted by Erik Rufelt on 03 July 2015 - 07:45 PM

Swap the red with the blue channel.




#5238021 Edge artifact with basic diffuse shading

Posted by Erik Rufelt on 02 July 2015 - 10:33 AM

Looks like you have face-culling disabled and the depth-buffer precision isn't enough to avoid Z-fighting at the edges.

Create a 24-bit depth-buffer, or increase the distance to your near-plane in the projection matrix, like changing 0.01 to 0.1 or even 1.




#5237697 Window-sized texture problems when nearing/exceeding screen size

Posted by Erik Rufelt on 30 June 2015 - 10:23 AM

Have you tried querying the window size as well as texture sizes?

Not sure what the SDL functions are, but you want to find the client area of the window, and then query your OpenGL textures for their size, with glGetTexLevelParameteriv, and the viewport with glGetIntegerv.




#5237275 How slow is reading render target data on the CPU?

Posted by Erik Rufelt on 28 June 2015 - 10:54 AM

Depends. You don't necessarily need to read back until you save, if you render into your vertex-buffer or read the same heightmap-texture from the vertex-shader that you write in the "edit" pixel-shader. The bandwidth for reading back will probably be several GB per second so it's not a problem in that way.. but if you start waiting every frame for such a read-back before sending the same data back to the GPU again to render it, latency could impact the framerate quite a bit. Hard to say before you try though.

Usually this performance is more about breaking synchronization and frame-buffering making it difficult to maintain proper 60 Hz vsync, but for an editor I wouldn't worry too much until you try it, unless it's very difficult to implement in which case you might want to draw up some sequence-diagrams of your intended framehandling and think about how it can be optimized before you spend time on something that might be too slow.




#5236732 The Story of a Roman Slave - 2D RPG set in an alternate history Britannia

Posted by Erik Rufelt on 25 June 2015 - 08:19 AM

Sounds awesome, but make it like 700-800 instead, in 1745 Britain was already pretty technologically advanced in the real world after spending 1500 years less so than the Romans. If Rome had not fallen I would rather expect your game to take place on Mars.

Secondly... for them to keep slaves seems somewhat unlikely in such a scenario. Slavery has rarely if ever kept societies very stable for long periods of time, and would probably require a society to settle into some sort of equilibrium where every generation lives the same as the last. Even Rome at its greatest had slave rebellions.

Perhaps they suffered some setbacks / war / population-decline 200 years earlier and resorted to slavery, and then it stuck around a generation or two too long even as new advancements where made. I guess such events could add a century or two to the timeline.

 

If you mean to make 1745 Britain seem sort of like real 1745 Britain but with cool technology I doubt that Rome is the right way to go. The society that dominated Britain after 1000 AD was extremely different to anything that existed in Roman days, and if Britain is supposed to have evolved for a millennium with Roman leaders it would be unrecognizable long before modern Europe had even begun to develop.




#5236648 Why does a Texture2D description require a sample description?

Posted by Erik Rufelt on 24 June 2015 - 07:38 PM

It's for multi-sampled textures, like a render-target, not the sampler-state. If you don't have 1 for the sample-count and want to sample the texture in a shader, you need to use a Texture2DMS instead of a Texture2D in the shader.

EDIT: (And D3D11_TEX2DMS_SRV in the view-dimension when creating the shader resource view. Similar for the render target view.)




#5236075 Perspective Distortion

Posted by Erik Rufelt on 21 June 2015 - 04:55 PM

LookAt looks incorrect as forward and up will not be perpendicular, so after you have calculated right you must re-calculate up from cross(right, forward). (Or cross(forward, right) perhaps..)




#5235676 [DirectWrite] Get GlyphRuns from the text

Posted by Erik Rufelt on 19 June 2015 - 07:06 AM

I see, I think misunderstood your question. If you want to measure the entire string, use a text layout, and when you want to measure only a glyph, there is for example GetDesignGlyphMetrics on a font face. Either way I think you probably want to cache these and not call DirectWrite more than necessary when you want good performance.

If you look through the MSDN pages for fonts/font-faces and text-layouts/formats there are many different ways to measure text, and get internal font parameters.

It really depends on exactly what you want to implement at a higher level, there are often several ways to do the same thing in DirectWrite.




#5232394 should WndProc process WM_QUIT?

Posted by Erik Rufelt on 02 June 2015 - 09:42 AM

1. No.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms632641%28v=vs.85%29.aspx

 

When GetMessage returns that it has received a WM_QUIT, your window will already be destroyed.

 

2. As WM_QUIT is detected in your main loop and not in the WndProc this isn't an issue, just exit when GetMessage returns 0. See docs for GetMessage and PeekMessage for details.




#5232199 IOCP shutdown design

Posted by Erik Rufelt on 01 June 2015 - 12:25 PM

Without any locks closesocket can be called on the socket before AcceptEx returns on another thread, no matter what you do.

AcceptEx can fail for other reasons than the listening socket being closed, so I don't really see the point, if you're trying to avoid AcceptEx returning an error?

 

You could write it so AcceptAsync never has to wait and only Stop waits if an AcceptEx is currently waiting to return.




#5231327 D3D11 How not to draw the pixel when alpha in texture is 0

Posted by Erik Rufelt on 27 May 2015 - 01:32 PM

You can use something like this:

if(textureColor.a < 0.1)
  discard;

Another alternative is alpha blending. If you don't use depth-testing, your sprites are drawn at 1:1 scale, and there is only 1.0 or 0.0 values for the alpha of a pixel the results will be identical.




#5229465 Thoughts and Ideas about optimizing 2D Per Pixel Collisions

Posted by Erik Rufelt on 17 May 2015 - 11:02 AM

Pre-save the collision masks instead of creating them from D3D memory, so they can just be read into an array. Requiring textures to be lockable and readable sounds like a bad idea. Should make loading time pretty close to zero too if you can just read the data from a file already in your internal collision mask format.






PARTNERS