SetViewPort Problem

BlitzMax Forums/BlitzMax Programming/SetViewPort Problem

Just for other users with the same problem. If you use the following code you can use SetViewPort/DrawImage as you are used to use them, but it will work on all graphic cards:

SuperStrict

Graphics 640,480,0

'Global Viewport coords
Global vx:Float, vy:Float, vw:Float, vh:Float

Local t:TImage = LoadImage ("gfx/mainmenu.png")
Local a:Int = 0
While(Not KeyDown(KEY_ESCAPE))
	a:+1
	Cls
	SetViewport2 200+(Sin(a)*100),200+(Cos(a)*100),100,100
	DrawImage2 t,-300,210	
	Flip
Wend

Function SetViewport2( x:Float, y:Float, width:Float, height:Float ) 
	vx = x
	vy = y
	vw = width
	vh = height
	SetViewport(x,y,width,height)	
End Function

Function DrawImage2(image:TImage, x:Float, y:Float, frame:Int=0)
	Local rx:Float = vx
	Local ry:Float = vy
	Local rw:Float = vw
	Local rh:Float = vh
	 
	rx:-x
	ry:-y

	x = vx 		
	y = vy
	
	If rx<0 Then rw:+rx ; x:-rx ; rx=0
	If ry<0 Then rh:+ry ; y:-ry ; ry=0	
	If rw<0 Then rw=0
	If rh<0 Then rh=0

	ccDrawImageArea(image,x,y,rx,ry,rw,rh,frame)
End Function

Function ccDrawImageArea(image:TImage, x#, y#, rx#, ry#, rw#, rh#, frame:Int=0)
  Local origin_x#, origin_y# ; GetOrigin (origin_x, origin_y)
  Local tw:Int = Pow2Size(image.width)
  Local th:Int = Pow2Size(image.height)
  Local rw1#  = rx + rw
  Local rh1#  = ry + rh
  Local x0# = -image.handle_x, x1# = x0 + rw
  Local y0# = -image.handle_y, y1# = y0 + rh
  
  If rw1 > image.width
    x1 = x0 + rw + image.width - rw1
    rw1 = image.width
  EndIf
   
  If rh1 > image.height
    y1 = y0 + rh + image.height - rh1
    rh1 = image.height
  EndIf
?Win32
  If TD3D7ImageFrame(image.frame(frame))
    Local frame:TD3D7ImageFrame = TD3D7ImageFrame(image.frame(frame))
    
    frame.setUV(rx / tw, ry / th, rw1 / tw, rh1 / th)
    frame.Draw x0, y0, x1, y1, x + origin_x, y + origin_y
    frame.setUV(0, 0, image.width / Float(tw), image.height / Float(th))
  Else
?
    Local frame:TGLImageFrame = TGLImageFrame (image.frame(frame))
                
    frame.u0 = rx / tw
    frame.v0 = ry / th
    frame.u1 = rw1 / tw
    frame.v1 = rh1 / th
    
    frame.Draw x0, y0, x1, y1, x + origin_x, y + origin_y
    
    frame.u0 = 0
    frame.v0 = 0
    frame.u1 = image.width / Float(tw)
    frame.v1 = image.height / Float(th)
?Win32
  EndIf
?
  
  Function Pow2Size:Int(n:Int)
    Local ry:Int = 1
    
    While ry:Int < n
      ry :* 2
    Wend
    
    Return ry
  End Function
End Function