Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Swatter555

Member Since 03 Jun 2003
Offline Last Active Jul 07 2013 09:14 PM

Topics I've Started

DPI awareness and a full-screen

29 June 2013 - 11:42 PM

I have been trying to Google combinations of those terms like crazy and I can find very little info. I am coding a full-screen application using the DIrect2D API, which automatically scales rendering to current DPI setting. That is all fine and dandy, but higher DPIs effectively decreases resolution. If I were creating a windowed app, I would create a larger window and everything would scale nicely. However, for full-screen, part of the screen is going to be clipped.

 

I have turned up very little info on my internet searches, so I am kinda stuck about what I should do. I could make the app use windowed mode, but that opens up a can of worms in itself. Direct2D uses dips for everything, so I don't think I can tell it not to scale things. What am I missing about DPI awareness and full-screen applications?

 

 

 

 


Direct2D: Strange behavior

18 April 2012 - 09:39 PM

I have created my own rendering engine using D2D and I have ran into problems much of the way, most of these problems have dealt with the windows message pump in one way or another. Each step of the way I tested and tested to make sure the code was solid, but I am getting some strange behavior when rendering my 2D hex map. During execution, everything seems to run fine, efficiently and as expected. However, randomly, at some point during execution the frame rate creeps to almost nothing. Sometimes it returns to normal, sometimes it doesn't. Generally, in debug mode, the game loop executes a couple million times a second (doesnt do much), while paint calls are made 33 times a second. When the slowdown occurs, both slow down to 17.

The code that renders the map is simply 2 nested for loops rendering a single small bitmap, nothing complicated going on (no other rendering occurring besides diag text). I suspect the message pump is to blame again and my lack of understanding about what is truly going on behind the scenes. I regulate the number of paint calls using SendMessage (WM_PAINT). Most programmers don't use Direct2D and dont have to deal with the windows message pump in game application settings, so I couldn't find any direct examples about how to regulate paint calls. I don't even know is that is related to the problem. I hesitate to post code because I truly have no idea what is going wrong. Any advice, suggestions? I plan to get a book dedicated to win32 programming when my budget allows, so cross that one off the list.

I found rendering textured quads so much simpler in D3D. I don't know if I am riding the new technological wave or barking up the wrong tree with Direct2D. There are some cool things on the horizon for Direct2D, so I hope I can resolve these issues.

C++ Win32- Resizing after resolution change(with D2D)

12 April 2012 - 04:41 AM

I am using a game window that sizes to current screen resolution. I am also rendering graphics with the Direct2D API, which is dependent on the windows message pump WM_PAINT messages. I am fiddling around with changing desktop resolution (as a user might) and trying to get not only the window to resize correctly, but also getting the RenderTarget to resize correctly. Without getting too far in the weeds, my RenderTarget is not resizing correctly immediately after res change (I am resizing it with LPARAM from the WinProc). It seems to be a timing issue, because I can minimize then reactivate and the RenderTarget sizes correctly. It seems like the LPARAM from the WinProc isn't passing the correct client size on the resizes that happen immediately after res change. Does that make any sense?


LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Get window width and height
UINT width = LOWORD(lParam);
UINT height = HIWORD(lParam);

//Route the message
switch(message)
{
case WM_CREATE:
  {
  }break;

case WM_DISPLAYCHANGE:
  {
   InvalidateRect(hwnd, NULL, false);
   //Entry into log
	CTools::GameLogAdd(false,"WM_DISPLAYCHANGE");
  }break;

case WM_SIZE:
  {
   //Resizes window and render target
   if(pApp->IsInitComplete())
   {
	//Resize the window
	pApp->GetD2DPtr()->OnResize(hwnd,width,height);
   }//end if
  
   if(SIZE_MINIMIZED == wParam)
   {
   }//end if
  
   if(SIZE_MAXIMIZED == wParam)
   {
   }//end if
  }break;

case WM_NCLBUTTONDOWN:
  {
   //Prevents user from moving window via title bar
   if (HTCAPTION == wParam) return 0;
  }break;

case WM_DESTROY:
  {
   PostQuitMessage(0);
   return 0;
  }break;

case WM_PAINT:
  {
   //Call Direct2D rendering routines
   if(pApp->IsInitComplete())
   {
	pView->OnPaint();
	ValidateRect(hwnd, NULL);
   }//end if
  }break;
case WM_KEYDOWN:
  {
   switch(wParam)
   {
   case VK_SPACE:
	{
	
	}break;
   }//end switch
  }break;

}//end switch

//Handle any remaining messages
return DefWindowProc (hwnd, message, wParam, lParam);
}




UINT CDirect2D::OnResize(HWND _hwnd,UINT _width,UINT _height)
{
//Check if window is able to be resized
if(!IsResizable())
  return FAIL;

//Get current screen size
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

//Reset window position
MoveWindow(_hwnd,0,0,width,height, true);

//Resize the Direct2D render target
GetRenderTarget()->Resize(D2D1::SizeU(_width, _height));

//Entry into log
CTools::GameLogAdd(false,"D2D OnResize: Called");

return SUCCESS;
}

Combining two textures

24 March 2007 - 07:43 AM

To be clear, I am not talking about alpha blending. I need to combine two textures together, I believe using the lock method. I cant seem to find the correct terms to google, so I will give it a try here. Now, I am trying to combine several textures together to form my 2d map tile. There could be so many potential "layers" that locking the texture and copying the next texture on top seems to be the best way. I am using an open source 3D engine (irrlicht) that doesnt like it when you directly uncover the directx pointers, but locking textures isnt a problem though. All of the textures I use are colorkeyed, so I need to preserve that. How can I properly perform those actions? If anyone knows of any links to a article that directly covers this, I would appreciate it.

Texture staging question

07 October 2006 - 05:48 AM

I am attempting to blend 3 textures together. The bottom layer is a map texture with landmasses. The middle layer is the detail texture. The top layer is the water the surrounds the landmasses from texture one. The top layer is loaded colorkeying out everything but the water. Now, the following code handles the first two textures(bot,mid):
device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); 
device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); 
device->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT ); 
device->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE ); 
device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED ); 

All of these state enumerations just make me want to tear my eyes out. Could someone show me how to put the third texture in there correctly? I would rather sort of work backwards and figure out why it works, rather than figuring out why it doesnt work. Thanks in advance :) Also, could someone direct me to their favorite tutorial on texture stage stuff.

PARTNERS