Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Erik Rufelt

Member Since 17 Apr 2002
Offline Last Active Yesterday, 09:29 PM

#5238288 How to correctly convert A8R8G8B8 texture?

Posted by Erik Rufelt on Yesterday, 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.



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)

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.

#5229333 Marvel/DC Comic Games Copyright / Royalty

Posted by Erik Rufelt on 16 May 2015 - 12:07 PM

There is absolutely no way you can do that, unless you pay them millions. Even so I doubt a company like Marvel would ever agree unless they got absolute say on every single design choice as well as whether or not the game would even be released once done, as protecting the reputation of their multi billion dollar franchise s more important than a single payday.

If you Google a bit you might be able to find info on how strict they are, some big companies will come after you right away to shut you down on principle, whereas some won't really care. In general you can't use any existing IP without express permission.

#5229213 When you realize how dumb a bug is...

Posted by Erik Rufelt on 15 May 2015 - 02:47 PM

Do you see it?


I thought it would be that 'y * w * x' should be 'y * w * n', missed the shadowing. :)

#5228185 Particle Distortion Effect

Posted by Erik Rufelt on 09 May 2015 - 05:22 PM

Render distortion areas to a distortion map or something? Use the refract() hlsl function?


Sounds reasonable.. probably need to tweak the shader a bit to get the look you want, not sure if refract is really the best fit for heat haze..


Google for "heat haze directx shader tutorial" or "post processing directx shader tutorial" and similar search terms, gives a few results, some threads here on Gamedev among others.