Filling space around a image

Started by Rooster, September 05, 2017, 03:06:26

Previous topic - Next topic

Rooster

Is there any way to fill in space around a image with a solid color?

I draw my game map as a single image for each layer (foreground, background...) .
Some times I will want to put windows in the background, and then use TileImage to draw two layers of moving stars, at a different speeds to create the effect of depth.
What I want to do is fill in the space around my game map with a solid color.

I could probably use GrabImage, but in my experience it's too slow.
The only other thing I could think of is just manually animating the background.

Is there any method or command to get around this?

degac

Hi
I don't clearly understand your question...
Quote
What I want to do is fill in the space around my game map with a solid color.
So you don't want to fill ONE IMAGE, just everything is shown on screen.

SetClsColor change the 'CLS' color (if you need this) and - assuming your image are 'transparent' - you should 'fill up' the space.

A second solution is to make a different version of any image - filled or not - and use it when needed.

If there's a problem, there's at least one solution.
www.blitzmax.org

IanMartin

You can use a blank pixmap in the color you want and paste the image into it.  This isn't a super quick thing though, something you'd probably want to do beforehand.
EditingPixmap.Paste (Pixmap32X32:TPixmap, 2, 2) will paste Pixmap32X32:TPixmap 2 pixels into EditingPixmap, for instance.

I'm not sure exactly what you are trying to achieve, there are probably better ways if we knew exactly what you're going for.

I second SetColor and CLS to set the whole background to one color.
Platfinity (made with BlitzMax) on Steam:
http://store.steampowered.com/app/365440/Platfinity/

TomToad

#3
Is this kind of like what you are after?


All i did here was use TileImage to draw the stars, then drew the background with a transparent windows over it.  If you need to limit the drawing to a certain area, say there are other transparent parts on the wall that you don't want stars to shine through or the wall graphic is too small to fill the screen, then you can use SetViewport to limit where the stars are rendered.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Rooster

Quote from: TomToad on September 05, 2017, 20:08:55
Is this kind of like what you are after?
Yes.
Quote from: TomToad on September 05, 2017, 20:08:55
If you need to limit the drawing to a certain area, say there are other transparent parts on the wall that you don't want stars to shine through or the wall graphic is too small to fill the screen, then you can use SetViewport to limit where the stars are rendered.
The last one is what I'm looking for. :)
I'd like to color in the area that isn't covered by the map image with a matching color.

I know I could use SetClsColor, and then use SetViewport. But for that I'd need two versions of the star image, one with a solid black background, and one with a alpha of zero.
That would probably be the best solutions, but it feels a little awkward.

Anyways, thanks TomToad. :)

TomToad

Quote from: Rooster on September 06, 2017, 00:02:08
But for that I'd need two versions of the star image, one with a solid black background, and one with a alpha of zero.
That would probably be the best solutions, but it feels a little awkward.

Or you can have one version with alpha set to 0 and color components set to black, then use SetBlend SOLIDBLEND to draw the image with the black background and SetBlend ALPHABLEND when you need to mask out the black background.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Rooster

#6
Okay, look like this will work, I just have one problem.

SOLIDBLEND seems to be making the star tiles draw with it puffy,



I have the code and image I was using below.


Global ty
Global ty2
Global tx
Global tx2

Graphics 800,600,0

Global img = LoadImage ("Tile_stars.png")

SetClsColor (100,100,100)

While Not KeyDown (27)

Cls

SetViewport (400,300,350,250)

  SetBlend SOLIDBLEND
  TileImage img,tx,ty,0 ' layer 1

  SetBlend ALPHABLEND
  TileImage img,tx2,ty2,0 'layer 2

ty:+2
ty2:+1
tx:+2
tx2:+1

SetViewport (0,0,800,600)

Flip

Wend

col

Hiya,

Cls affects only the active viewport area. This means that you can use the Cls twice for your example to work without any need to use SetBlend. Of course this just gets your example working and it may not be what you need to use for your final render.

Global ty
Global ty2
Global tx
Global tx2

Graphics 800,600,0

Global img = LoadImage ("Tile_stars.png")

While Not KeyDown (27)

  ' clear background to a colour
  SetViewport (0,0,800,600)
  SetClsColor (100,100,100)
  Cls

  ' clear the viewport sized background to another colour
  SetViewport (400,300,350,250)
  SetClsColor (0,0,0)
  Cls

  TileImage img,tx,ty,0 ' layer 1
  TileImage img,tx2,ty2,0 'layer 2

ty:+2
ty2:+1
tx:+2
tx2:+1

Flip

Wend
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Rooster

@col
That's really clever. ;)
I think I can get this setup to work.

I still would like to know why SOLIDBLEND was doing that.

Thanks for your help guys. :)

TomToad

Quote from: Rooster on September 06, 2017, 02:51:02
Okay, look like this will work, I just have one problem.

SOLIDBLEND seems to be making the star tiles draw with it puffy,


I have the code and image I was using below.


Global ty
Global ty2
Global tx
Global tx2

Graphics 800,600,0

Global img = LoadImage ("Tile_stars.png")

SetClsColor (100,100,100)

While Not KeyDown (27)

Cls

SetViewport (400,300,350,250)

  SetBlend SOLIDBLEND
  TileImage img,tx,ty,0 ' layer 1

  SetBlend ALPHABLEND
  TileImage img,tx2,ty2,0 'layer 2

ty:+2
ty2:+1
tx:+2
tx2:+1

SetViewport (0,0,800,600)

Flip

Wend


They still haven't fixed that problem?  I have an example I posted to the BM forums that is still using FlushMem()  :D  The fix I had for it is to load the image with the flags set to 0. LoadImage("ImageName.png",0)

You can also use Col's idea of Cls twice, or even just draw a black rectangle where you need the screen to be cleared.
------------------------------------------------
8 rabbits equals 1 rabbyte.

col

#10
On top of which my solution will not work 'as-is' with Dx11 ::)
Microsoft again...
https://msdn.microsoft.com/en-us/library/windows/desktop/ff476388(v=vs.85).aspx

Under the Remarks section :-
They decided that the 'clear render target' command isn't going to take the viewport and scissor settings into consideration. I guess this is an efficiency thing. I'm using this method inside the Cls function in the d3d11 driver so I think I should change the way this is working to fit better with the original BMax function expectation.

In the meantime using TomToad's suggestion of rendering a rectangle of your chosen colour where you need to 'Cls' would cover all of the BMax drivers:

Global ty
Global ty2
Global tx
Global tx2

Graphics 800,600,0

Global img = LoadImage ("Tile_stars.png")

SetClsColor (100,100,100)

While Not KeyDown (27)
' clear the complete background
SetViewport (0,0,800,600)
Cls

' clear a viewport area
Local cr,cg,cb
GetColor cr,cg,cb
SetColor 0,0,0
DrawRect 400,300,350,250
SetColor cr,cg,cb

' draw into the viewport area
SetViewport (400,300,350,250)
TileImage img,tx,ty,0 ' layer 1
TileImage img,tx2,ty2,0 'layer 2

ty:+2
ty2:+1
tx:+2
tx2:+1

Flip

Wend

https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Rooster

Quote from: col on September 06, 2017, 11:09:11
On top of which my solution will not work 'as-is' with Dx11 ::)
Microsoft again...
Curse you Microsoft!

I'm glad you brought that up col, I would not have noticed it till I tried to make a Widows build. :P

Thanks!