• Advertisement

BrynAspestrand

Member
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

129 Neutral

About BrynAspestrand

  • Rank
    Newbie
  1. problems with glBlendFunc

    Hi. Any help here would be greatly appreciated. I'm using a glOrtho view to draw a number of 2D sprites to the screen. What I want is that any sprites near the edges of the screen are faded to completely transparent from 100% opacity to 0% over a distance of 50 pixels. The sprites are rotated so I don't really want to calculate a bunch of smaller polygons and set the colors of each vertex appropriately. So my solution was to do the following: 1. Draw the background image with all alpha values set to 1.0 2. Set the blending mode to: glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO); 3. Draw a quad on the left edge of the screen (width=50, height=screenheight) the quad is a gradient that uses the colors: glColor4f(0.0f, 0.0f, 0.0f, 1.0f); for the right edge and glColor4f(0.0f, 0.0f, 0.0f, 0.0f); for the left edge 4. This should write only alpha values to the background image making an invisible alpha gradient in that rect 5. Set the blending func/equation to ???????????? 6. Draw my sprites all over the screen, some of which will intersect the gradient rect on the left edge and hopefully the pixels that make up the sprites will fade to the background image the closer they get to the left edge So my problem is step 5. I've tried setting the blend mode to: glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); but, while it does fade my sprites, it ignores the alpha channels of my sprites so all nice feathered edges and holes in the sprite are filled in to 100% opacity before being faded. Can anyone help me figure out the right combination of glBlendFunc/glBlendFuncSeparate/glBlendEquation/glBlendEquationSeparate I'm supposed to be using? Thanks!
  2. glBlendFunc problem

    Hi. Any help here would be greatly appreciated. I'm using a glOrtho view to draw a number of 2D sprites to the screen. What I want is that any sprites near the edges of the screen are faded to completely transparent from 100% opacity to 0% over a distance of 50 pixels. The sprites are rotated so I don't really want to calculate a bunch of smaller polygons and set the colors of each vertex appropriately. So my solution was to do the following: 1. Draw the background image with all alpha values set to 1.0 2. Set the blending mode to: glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO); 3. Draw a quad on the left edge of the screen (width=50, height=screenheight) the quad is a gradient that uses the colors: glColor4f(0.0f, 0.0f, 0.0f, 1.0f); for the right edge and glColor4f(0.0f, 0.0f, 0.0f, 0.0f); for the left edge 4. This should write only alpha values to the background image making an invisible alpha gradient in that rect 5. Set the blending func/equation to ???????????? 6. Draw my sprites all over the screen, some of which will intersect the gradient rect on the left edge and hopefully the pixels that make up the sprites will fade to the background image the closer they get to the left edge So my problem is step 5. I've tried setting the blend mode to: glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); but, while it does fade my sprites, it ignores the alpha channels of my sprites so all nice feathered edges and holes in the sprite are filled in to 100% opacity before being faded. Can anyone help me figure out the right combination of glBlendFunc/glBlendFuncSeparate/glBlendEquation/glBlendEquationSeparate I'm supposed to be using? Thanks!
  3. OK, so here's my problem. I've created an MFC CWnd class that wraps DirectDraw. I'm trying to use Blt to stick an image onto the surface used to draw the CWnd in its OnPaint handler Here's what I do (Note: I'm using LPDIRECTDRAWSURFACE, LPDIRECTDRAW, and DDSURFACEDESC... Not LPDIRECTDRAWSURFACE7, LPDIRECTDRAW7, and DDSURFACEDESC2... and my video card is incredibly bad) 1. I create the front surface for the CWnd using the following surface description: SurfDesc.dwSize = sizeof(SurfDesc); SurfDesc.dwFlags = DDSD_CAPS; SurfDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; 2. I create a back surface for flipping using this description SurfDesc.dwSize = sizeof(SurfDesc); SurfDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; SurfDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; SurfDesc.dwWidth = in_unWidth; SurfDesc.dwHeight = in_unHeight; 3. I create a 3rd surface that I want to use Blt to draw to the back surface. (in_bmp is the bitmap class that stores my image) Desc.dwSize = sizeof(Desc); Desc.dwWidth = in_bmp.GetWidth(); Desc.dwHeight = in_bmp.GetHeight(); Desc.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT; Desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; Desc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); Desc.ddpfPixelFormat.dwFlags = DDPF_RGB; Desc.ddpfPixelFormat.dwRGBBitCount = 32; Desc.ddpfPixelFormat.dwRBitMask = 0x000000FF; Desc.ddpfPixelFormat.dwGBitMask = 0x0000FF00; Desc.ddpfPixelFormat.dwBBitMask = 0x00FF0000; 4. I fill the 3rd surface with a test image and if I lock it, I can see in the mem view in Visual Studio that there is valid image data there. 5. The code works such that - the back surface is cleared m_pBack->Blt(rcClear, NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT, &BltFX); *WORKS!!!* - the back surface get's locked m_pBack->Lock(NULL, &SurfDesc, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT, NULL) *WORKS!!!* - some things get drawn to the back surface *Nothing right now but potentially there is something drawn* - the back surface get's unlocked *WORKS!!!* - the 3rd surface is Blted to the back surface using: m_pBack->Blt(&rcDst, in_pSrc, &rcSrc, DDBLT_WAIT, NULL); *works only if rcDst and rcSrc are the same width and height!!!* - the back is locked again - a few more things are drawn to the back surface - the back is unlocked a final time - the back is flipped to the front m_pFront->Blt(&rcDest, m_pBack, &rcSrc, DDBLT_WAIT, NULL); *WORKS!!!* Sorry for the long description... my question is why does Blt fail when I'm trying to scale? Blt succeeds everywhere else in the code. And even when I use different sized rects for the src and dst, the return code is S_OK. But instead of drawing a scaled version of the 3rd surface, it draws a dark blue-gray rectangle. Somebody please help. This is very frustrating!!! :)
  • Advertisement