Jump to content

  • Log In with Google      Sign In   
  • Create Account


Erik Rufelt

Member Since 17 Apr 2002
Online Last Active Today, 12:12 PM
*****

#5128190 OpenGL Alpha problem.

Posted by Erik Rufelt on 02 February 2014 - 10:43 AM

Depth or stencil testing is an easy way to achieve that, especially if there's no such testing used for other things, as they can be dedicated to providing non-overlapping shadows.

 

Another way is to use a back-buffer with an alpha channel, and draw everything with alpha zero except for shadows which are drawn with color-masking to only draw alpha at 50%. Then when all shadows and sprites are drawn, draw a black square over the entire screen with (GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA) to fill in the shadows.

 

EDIT: (It can also be done the other way around with everything else at alpha 1.0, which is probably easier).




#5128050 OpenGL Alpha problem.

Posted by Erik Rufelt on 01 February 2014 - 05:45 PM

You can draw them with depth-testing, so that they never overdraw each other. Draw the one that is supposed to be in front first, then with depth-testing enabled the one that is supposed to be behind it will not be drawn, if it's drawn at an appropriate Z. (For example same Z and a depth-test that is GL_NOTEQUAL).




#5127187 Why doesn't screen tearing happen at 5 fps?

Posted by Erik Rufelt on 29 January 2014 - 06:34 AM

If VSync is off it does happen below 60, even at 5. However it disappears again after 17 ms, even when the image is updated only after 200 ms, so you don't really notice it.




#5126034 SwapChain resize questions

Posted by Erik Rufelt on 23 January 2014 - 11:26 PM

No, it is handled by the swap-chain and you shouldn't have to care at all, you still use only one render-target.

Also, you're only resizing the swap-chain, and the swap-chain in turn resizes its buffers and anything else that might be needed for its internal workings. Just make sure to release all references to the back-buffer before resizing the swap-chain (as you already do).




#5125786 SwapChain resize questions

Posted by Erik Rufelt on 22 January 2014 - 10:59 PM

How do you create your window and window-class?

Make sure to have NULL as the background brush in window-class, and remove CS_HREDRAW and similar if you have them.

 

I would use ClearState in resize and then reset everything after:

// Release
pDeviceContext->ClearState();
pRenderTargetView->Release();
pDepthStencilView->Release();// Release both buffer and view
pDepthStencilBuffer->Release();// Release both buffer and view

// Resize
pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

// New back-buffer and render-target view
ID3D11Texture2D pBackBuffer;
pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);

ID3D11RenderTargetView pRenderTargetView;
pDevice->CreateRenderTargetView(pBackBuffer, ..., &pRenderTargetView);

// Save desc before release backbuffer
D3D11_TEXTURE2D_DESC;
pBackBuffer->GetDesc(&backBufferDesc);

pBackBuffer->Release();


// New depth-stencil
D3D11_TEXTURE2D_DESC depthStencilDesc = backBufferDesc;
depthStencilDesc.Format = DEPTH FORMAT;
...

pDevice->CreateTexture2D(&depthStencilDesc, &pDepthStencilBuffer);

pDevice->CreateDepthStencilVile(pDepthStencilBuffer, &pDepthStencilView);


// Set render target
pDeviceContext->OMSetRenderTargets(pRenderTargetView, pDepthStencilView);

// Set everything else
pDeviceContext->.. SetViewport(...);
pDeviceContext->.. SetDepthStencilState(...);
pDeviceContext->.. SetRasterizerState(...);
pDeviceContext->.. Set........(...);




#5123822 Text rendering - Minification?

Posted by Erik Rufelt on 15 January 2014 - 03:38 AM

To get proper mipmap usage you need padding between the glyphs that match the number of mipmaps. For example if you have 2 mip-levels (original image + one scaled to half size), the glyphs must be aligned on 2-pixel boundaries and must have two pixels padding between them (to avoid texture filtering to cause bleeding of adjacent glyphs in the texture).

If you need another mip-level, that requires 4-pixel alignment, and the next 8 pixels.

 

If your original glyphs are 32x32 and you allow two extra mip-levels that will be 16x16 and 8x8 and smaller glyphs than that probably aren't readable anyway so I wouldn't allow smaller mipmaps but let them pixelize if they get smaller (so just create the texture with only 3 mip-levels).




#5120694 Prevent WPF window redrawduring resizing

Posted by Erik Rufelt on 02 January 2014 - 09:02 AM

I can't help but feel this should be settable in XAML or something. I don't know, and since no one else answered for several days maybe try another forum with WPF-people, or ask again after the holidays when people are back.

 

 

If you want to hack it with SetWindowLongPtr it works something like this (pseudo-code,):

WNDPROC oldWndProc = NULL;

static LRESULT CALLBACK MyWndProc(...) {
   if(msg == WM_ERASEBKGND)
      return 1;
   else
      return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam);
}

...

myOverride() {
    LongPtr result = SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LongPtr)MyWndProc);
    oldWndProc = (WNDPROC)result;
}

I would also try Googling for D3D in WPF window flicker. There are several results for people trying to do this. There seems to be an easier way to replace the Wnd-proc than using SetWindowLongPtr: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc%28v=vs.110%29.aspx

 

(Maybe you should also override WM_PAINT and validate the window so it doesn't attempt to redraw again. If WPF is at all meant to be used with D3D then there should be built-in ways do do this, such as a specialized D3D image control or something so you don't have to hack it like this).




#5119894 D3D11 Rendering in other thread, window in Main thread

Posted by Erik Rufelt on 29 December 2013 - 02:30 PM

Not sure, I haven't used it. Try setting the background to transparent if possible.

I Googled it and many people have the problem. Seems like you can override hbrBackground by using SetClassLong, or use D3DImage to do your drawing. Not sure how it plays with multi-threading. I would create a new topic asking about WPF DirectX flickering issue specifically, and maybe someone knows how to solve it the best way.




#5119887 D3D11 Rendering in other thread, window in Main thread

Posted by Erik Rufelt on 29 December 2013 - 01:18 PM

How do you create your window and window-class?

My guess is you set a white brush to the window-class hbrBackground, and DefWindowProc uses it to erase the window. If set to NULL, then the window will not be erased. You can also handle WM_ERASEBKGND and return non-zero from your WndProc.

 

If you use CS_HREDRAW or CS_VREDRAW for your window-class I would also remove those, as those tell Windows to redraw the window when resized.




#5119810 D3D11 Rendering in other thread, window in Main thread

Posted by Erik Rufelt on 29 December 2013 - 07:15 AM

Do you resize on the main thread when you get a resize message?

That won't work as the render thread might be busy with the back-buffer. You should atomically set width and height variables, and then at the beginning of every frame on the render thread check if the swap-chain needs to be resized, or similar. You shouldn't touch the same device-context on multiple threads simultaneously.




#5119683 D3D11 Rendering in other thread, window in Main thread

Posted by Erik Rufelt on 28 December 2013 - 11:34 AM

Yes, but GetMessage works a bit differently. It only returns when there is a message available, and returns 0 on WM_QUIT.

So:

while(!done) {
	MSG msg;
	BOOL bRet = GetMessage(&msg, NULL, 0, 0);
	if(bRet > 0) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	else {
		done = true;
	}
}



#5115823 Making good use of multiple video cards on Windows 7 or 8

Posted by Erik Rufelt on 09 December 2013 - 10:14 PM


2) You can definitely do this in D3D11, so I would assume that you would be able to it in OpenGL as well

 

Unfortunately you can't in OpenGL usually. It requires extensions that are only available with drivers for the work-station cards, such as NVidia Quadro. I've read that AMD drivers will be nice and use the correct card depending on which monitor your window is created on, if both cards use the same driver, but I haven't tested it.

If the cards are from different vendors it always uses the card which has the primary monitor. Standard WGL does not have functionality for it.

 

(Which is completely dumb as you can actually create one OpenGL context on one card, then go into the display settings dialog and change the primary monitor to be on the other card, and then create the next context, and both work side by side correctly using the different cards. I've tested that on Win7 for AMD + NVidia and it works well, it's just that the pixel formats and driver is always chosen from the primary monitor).




#5115447 Help me get rid of this goto!

Posted by Erik Rufelt on 08 December 2013 - 02:47 PM

void COpenGL::LoadTexture(BYTE *pTex, UINT w, UINT h, UINT bpp, UINT format)
{
	if(!IsInitialized())
		return;
	
	if(Texture.ID == 0 || Texture.Width != w || Texture.Height != h || Texture.BPP != bpp || Texture.Format != format) {
		if(Texture.ID != 0)
			DeleteTexture();
		
		CreateTexture();
		
		Texture.Width = w;
		Texture.Height = h;
		Texture.BPP = bpp;
		Texture.Format = format;
		
		glTexImage2D(GL_TEXTURE_2D, 0, Texture.BPP, Texture.Width, Texture.Height, 0, Texture.Format, GL_UNSIGNED_BYTE, pTex);
	}
	else {
		glBindTexture(GL_TEXTURE_2D, Texture.ID);
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, Texture.Width, Texture.Height, Texture.Format, GL_UNSIGNED_BYTE, pTex);
	}
}



#5113349 The idea of mixing JRPG and Western RPG's into one game?

Posted by Erik Rufelt on 30 November 2013 - 03:48 PM


This part was the actual paragraph to make sense to me to be honest lol I see alot of potential on where i can go with the party aspect. I actually have a few gameplay/story mechanics that the party will have, in the sense of tying characters to other places. So what you said actually helped out alot in the sense of creating emotion through my characters and somehow creating stories in other parts of the game's world.

 

Sounds like a great place to start, and can surely lead to a great game.

 

 


But there was some advice that you gave that just made me go ''O _ O wait what?'' like:

 

I think a lot of my posts is just throwing several ideas out at once, as I don't I feel I have a complete sense of what could work and what couldn't, as probably no one does or the game would already exist. :)

 


Does this mean that manually creating a decision tree for an open world with this concept will be close to impossible to do? o _o?

 

Not necessarily, I think the party aspect could make it possible. As your party is always with you, the building blocks for emotional development is always right there. It would be much easier to fill the world with elements that triggered such development in the party, rather than for example making the world or an NPC have very complicated development depending on the players actions. Also, if there is a complicated development in the world, then the player would have to come back to that place all the time to benefit from it, while as the party moves with the player the rewards for an achievement always stay with the player.

In Skyrim the only thing that really stays with you while exploring is your armor and your skills.

 

If the party is the main source of attachment for the player, it will also be easier to keep the complicated decision trees more manageable, and for the world outside the party, simpler decision trees might pass as more acceptable.

 


So what you are saying is to make the actual open world a real time simulation of stories going on? And the player can choose which story he puts himself in? by for example, finding the X area by chance and triggering a storyline?

 

Something like that. This part of my post was just a theory on how one might imagine implementing something that at the moment feels rather impossible to implement, and I don't think I really have anything substantial on that. :) Basically just replacing the ever-present writer with a reasonable emotional simulation that works hand in hand with certain predesigned story elements. For example there are chat-bots that are quite difficult to distinguish from real people, and one could imagine developing such a bot into a character in the game, and having them follow certain story lines to the best of their simulated ability. Again, nothing that's realistic to combine with a real story right now, but sooner or later it will probably be done.




#5113334 The idea of mixing JRPG and Western RPG's into one game?

Posted by Erik Rufelt on 30 November 2013 - 02:22 PM

Sounds like a good premise. The main problem that I see is that it simply becomes too big before it can fill an open world the size of Skyrim's. There will need to be such a large decision-tree that it will be very difficult to manually create all the branches.

 

Because of this I somehow imagine that to reach something like that we might be better off to not make the game player-driven, in the sense that the game is instead a long movie of N number of hours that plays through no matter if the player moves from his starting position or not, and he only chooses his place in this movie. Then the difficult part in creating such a game is to make it possible for the player to find his way into interesting parts of the movie, and to decide how much he can actually influence the plot. But that's just one guess, theoretically anything could be done.

The advantage of such an approach is that it makes the decision tree smaller, as the world only needs be filled for a certain number of hours.

 

In a perfect scenario a writer would sit behind the monitor and write the story as the player goes along, determining each NPC decision based on what the player does. As the number of choices and the size of the world grows, the number of decisions becomes so huge that they cannot possibly all be written in advance. I think that is where Skyrim falls short, in that there are a few small dots in the world where there is an actual story, and the rest is an empty world, so that's where they try to create a balance where a large part of the game is instead about exploring or fighting or leveling up, because filling the whole world with story just isn't realistically doable.

 

I think the party aspect sounds very good, and might in itself solve a lot of the problems. If you create interaction between the members of your party, and allows the player to choose which of his party members desires to follow, and perhaps give each party member an emotional tie to different parts of the world, that could create a much more emotional experience. Come to think of it, that might well be the best part of such RPGs, the emotional part is very often about what happens to the members of your party.

In Skyrim you are supposed to play yourself, you can customize your characters to your liking, while in the story centered RPGs the game is about you as the player fighting for the members of your party.

So the real challenge might be in making an open world make sense for a party-driven game. This is already somehow solved for MMORPGs where the party is real people, but for a story-driven game the characters would need to be written so there is emotional benefit in exploring the world.






PARTNERS