drawpoly and mix-in openGL problems

BlitzMax Forums/BlitzMax Programming/drawpoly and mix-in openGL problems

Will(Posted 2007) [#1]
[Edit - the same problem occurs without the openGL, simply using setOrigin - I have created a new topic to discuss it rather than this one, since it isn't possible to edit post title, and I think people will be scared off by the mix-OpenGL one, and I need some help on this :p)

I have some code which lets me move and rotate the view around, it's included at the end of this post.

The trouble is, when I use drawpoly with it, polys with points far outside the view have their shape changed when drawn - at least one offscreen point seems to get moved, changing the shape of the poly.

Any idea how I can get around this, or fix it?

Here's the openGL I'm using to transform the view:

Excerpt I expect is the relevant part:
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluOrtho2D(LeftEdge, rightEdge, bottomEdge, TopEdge)
	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
	glTranslateF(xpos,ypos,0)
	glrotateF(Rotation, 0, 0, 1)
	glTranslateF(-xpos,-ypos,0)


And for the curious full view orientation code:
'View Orientations

SetGraphicsDriver(GLMax2DDriver()) 'make sure we are in openGL as these only work for OGL


Type ViewOrientation
	Global initialized
	
	Global current:viewOrientation
	
	Field selfInitialized
	
	Field leftEdge#
	Field rightEdge#
	Field bottomEdge#
	Field topEdge#
	
	Field XPos#, YPos#, Zoom#=1, Rotation#=0
	Field vpSavedX#, vpSavedY#
	
	Global realwidth#
	Global realheight#
	
	Global vpX, vpY
	Global currentWidth#
	Global currentHeight#
	
	Global naturalZoom#
	
	Function init()
		If realwidth <> GraphicsWidth() Or realheight <> GraphicsHeight() Or (initialized = False And GraphicsHeight() <> 0) Then
			initialized = True
			naturalZoom = GraphicsHeight() / 768.0
			realwidth = GraphicsWidth()
			realheight = GraphicsHeight()
			currentWidth = realWidth
			currentHeight = realHeight
		End If
	End Function
	
	Function clear:viewOrientation()
		nv:viewOrientation = New vieworientation
		nv.apply()
		Return nv
	End Function
	
	Method New()
		init()
		selfInit()
	End Method
	
	Method selfInit()
		If selfInitialized = True Or GraphicsHeight() = 0 Then Return
		
		selfInitialized = True
		
		leftEdge = 0
		rightEdge = GraphicsWidth()
		topedge = 0
		bottomEdge = GraphicsHeight()
		
		XPos = GraphicsWidth()/2
		YPos = GraphicsHeight()/2
	End Method
	
	Method move(x#, y#, rot#=0)
		setXYZoomRot(XPos + x, Ypos + y, Zoom, Rotation + rot)
	End Method
	
	Method setXY(x#, y#)
		setX(x); setY(y)
	End Method
	
	Method setXYZoomRot(x#, y#, Z#, R#)
		setX(x); setY(y)
		setZoom(Z); SetRotation(R)
	End Method
	
	Method setXYH(x#, y#, h#)
		setZoom(realheight / h)
		setxy(x + (rightEdge-leftEdge)*.5, y + (bottomEdge-topedge)*.5)
	End Method
	
	Method setX(x#)
		XPos = x
		calculate()
	End Method
	
	Method setY(y#)
		YPos = y
		calculate()
	End Method
	
	Method setZoom(Z#)
		Zoom = Z
		calculate()
	End Method
	
	Method SetRotation(rot#)
		Rotataion = rot
		calculate()
	End Method
	
	Method Apply()
		selfInit()
		init()
		
		calculate()
		
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		gluOrtho2D(LeftEdge, rightEdge, bottomEdge, TopEdge)
		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()
		glTranslateF(xpos,ypos,0)
		glrotateF(Rotation, 0, 0, 1)
		glTranslateF(-xpos,-ypos,0)
		
		current = Self
		
	End Method
	
	Method calculate()
		selfInit()
		
		realZoom# = Zoom
		
		vpSavedX = vpX
		vpSavedY = vpY

		If realZoom = 0 Then Zoom = .00001
		LeftEdge = xpos - ((currentWidth / Zoom) / 2)
		rightEdge = xpos + ((currentWidth / Zoom) / 2)
		topEdge = ypos - ((currentHeight / Zoom) / 2)
		bottomEdge = ypos + ((currentHeight / Zoom) / 2)		
	End Method
	
	Method screenSpaceToWorldSpace(wx# Var, wy# Var)
		wx:-vpSavedX
		wy:-vpSavedY
		wx:/zoom
		wy:/zoom
		wx:+leftEdge
		wy:+topEdge
	End Method
	
	Method worldSpaceToScreenSpace(wx# Var, wy# Var)
		wx:-leftEdge
		wy:-topedge
		wx:*zoom
		wy:*zoom
		wx:+vpSavedX
		wy:+vpSavedY
	End Method
	
	Method onScreen(wx#, wy#, radius#)
		wx:-leftEdge
		wy:-topedge
		wx:*zoom
		wy:*zoom
		radius:*zoom
		
		If wy + radius < 0 Or wy - radius > realheight Then Return 0
		If wx + radius < 0 Or wx - radius > realwidth Then Return 0
		
		Return 1
	End Method
	
	Function SetViewport(x,y,width,height)
		GLViewPort(x, GraphicsHeight() - y - height, width, height)
		
		vpX = x; vpY = y
		currentHeight = height
		currentWidth = width
		
		If current <> Null Then current.apply()
		
	End Function
	
	Function ClearViewport()
		ViewOrientation.SetViewport(0,0,GraphicsWidth(), GraphicsHeight())
		currentWidth = realWidth
		currentHeight = realheight
	End Function
	
End Type



ImaginaryHuman(Posted 2007) [#2]
Clip your polygon?


Will(Posted 2007) [#3]
Update: problem happens regardless of using the openGL code in my post, whenever using openGL max2d with setorigin

Update: problem only seems to exist on macbooks

Update: different thread started