Displaying part of an image?

BlitzMax Forums/BlitzMax Beginners Area/Displaying part of an image?

jp22(Posted 2008) [#1]
Sorry - posted this in B3D forum, when I meant it to go here..

How do I display a section of an image (like DrawImageRect does for B3D / B+ ?)

I've an image which I need to display just a section of. For example, a 128*128 image, but I just need to display a 32*32 section from starting point X=10, Y=50

Thanks!


tonyg(Posted 2008) [#2]
The command doesn't appear which has always been an odd omission (there are others as well).
There's a few different approaches in Code Archives / Graphics / bmx by doing a find with drawimagerect or drawimagearea.
I check all the available ones and this is my favourite.


jp22(Posted 2008) [#3]
Thanks Tonyg

That got me out of a fix.

I can't find any help info about TD3D7Imageframe from the BMax hel. I'd like to know more about this, as it seems pretty powerful. Can you/anyone point me into the right direction for a dummies guide to this !

Thanks again


tonyg(Posted 2008) [#4]
You will need to check the source for information. However, it is BRLs internal object for hold imageframe instances. Each time you loadimage it will be created under the covers.
It's certainly not 'Beginners' material but hope it helps.


Dreamora(Posted 2008) [#5]
There is no documentation as the imageframe is an internally only used thing. I you want to really use it you must do that within the module itself as some stuff is privated so external access is impossible.

and messing with it can lead to straight crashes if you do not have an idea what you are doing ...
So if you think that Blitz3Ds surface - addvertex etc commands are to complicated, better don't touch it.


xMicky(Posted 2008) [#6]
What about a simple solution like this ?
Strict

Graphics 640, 480, 0
SetClsColor 166, 166, 166

'make us an image for demonstration purpose
SetBlend SOLIDBLEND
SetMaskColor 0, 0, 0
SetColor 255, 0, 0
DrawRect 0, 0, 64, 64
SetColor 255, 255, 255
DrawRect 64, 0, 64, 64
SetColor 0, 0, 255
DrawRect 0, 64, 64, 64
SetColor 255, 255, 0
DrawRect 64, 64, 64, 64

Local curImgHandle:TImage =CreateImage(128, 128, 1, DYNAMICIMAGE | MASKEDIMAGE)
GrabImage curImgHandle, 0, 0

SetBlend ALPHABLEND
SetColor 255, 255, 255

Local offsetX:Int =47
Local offsetY:Int =37
Repeat

  Cls

  DrawText "original image", 75, 80
  DrawImage curImgHandle, 75, 100

  DrawText "image drawn as 32 x 32 from :" +offsetX +", "+offsetY, 250, 80
  DrawText "(use arrow keys and home to change display)", 250, 150

  SetViewport 250, 100, 32, 32 'desired location and with of images displayed part
  DrawImage curImgHandle, 250 -offsetX, 100 -offsetY
  'change displayed part of image
  If KeyDown(KEY_LEFT) Then
    offsetX :-1
  ElseIf KeyDown(KEY_RIGHT) Then
    offsetX :+1
  ElseIf KeyDown(KEY_UP) Then
    offsetY :-1
  ElseIf KeyDown(KEY_DOWN) Then
    offsetY :+1
  ElseIf KeyDown(KEY_HOME) Then
    offsetX =47
    offsetY =37
  End If
  offsetX =Abs(offsetX Mod (128 -32))
  offsetY =Abs(offsetY Mod (128 -32))

  SetViewport 0, 0, 640, 480

  Flip

Until KeyHit(KEY_ESCAPE)



tonyg(Posted 2008) [#7]
Nothing wrong with that except there are reports of setviewport not working properly on some cards.


xMicky(Posted 2008) [#8]
As far as I know it is Grey Alien only, who mentioned this issue. He also posted some code for displaying parts of Images without using SetViewport, it can be found here:

gah! How to clip rotated rectangles.

[Edit]Ah, just saw your link above, tonyg, there are already code samples. OK, then it seems here is everything said to the topic what we can currently say about it.

My personal opinion to the SetViewport-does-not-work-thingy is however: If BRL sees no necessity to change the implementation, I myself also see no need for a workaround. There are obviously always some things, which will not work on one Computer or another , and who knows whether the workaround for SetViewport will not fail again on other machines.


tonyg(Posted 2008) [#9]
I do have some setviewport issues on my machine but only when using the card with low-level DX stuff. I agree that it shouldn't prevent anybody using it but it's always nice to have an alternative solution.
Personally, I would love to hear from BRL why some staples of B2D/B3D didn't get incorporated into BMax and why they're still missing.


jp22(Posted 2008) [#10]
Thanks again for this info.

Just curious: Which is faster? Viewport or TD3D7Imageframe ?

I'm guessing that if ViewPort method involves memcopies, this would be noticably slower with larger images.


Dreamora(Posted 2008) [#11]
Wrong.

Viewport uses 3D view frustrum clip planes (dx) or scissor tests (gl which does the same). There is no copy involved.

But thats the reason the image frame approach is faster. Its faster because if you use various frames of that images in one go (without changing image) the hardware can remain on that single texture and do it.
This allows you to speed up the whole stuff by not altering anything than the geometry.

Viewports on the other end always requests changes on the GPU when rendering, which costs time.


CS_TBL(Posted 2008) [#12]
The viewport thing also doesn't work on my videocard (Geforce 4mx)..


Dreamora(Posted 2008) [#13]
Yes, your card is a GF2 modified ... does not support more than 2 Clipplanes (was a DX7 card and 3+ clip planes are DX8+. And viewport actually need 4 clipplanes)


tonyg(Posted 2008) [#14]
You can use this with
Graphics 640,480
Local mycaps:TG_D3DDEVICEDESC7 = New TG_D3DDEVICEDESC7
D3D7GraphicsDriver().Direct3DDevice7().getcaps mycaps
Print mycaps.wMaxUserClipPlanes

to see how many clip planes your card supports.
I wonder why Bmax doesn't use a real DX viewport?