Bug Scissor issue

magic

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
226
I come across a few problems with SetScissor().
The first problem looks like a bug or some error in re-setting the SetScissor bound.

Scissor1.gif

Refer to the above picture: I set the scissor about 10 pixels margin on the white rectangle box.
As I move the box, the scissor should follow. But when the box X is less than 0, it seems that the scissor is altered its location. That is weird

My code is here
Code:
Import mojo2
Function Main();New MyApp;End
Class MyApp Extends App
    Field x,y,width=100,height=100
    Field margin=10
    Field c:Canvas
    Method OnCreate()
        c=New Canvas()
    End
    Method OnUpdate()
        x=MouseX()
        y=MouseY()
     End
    Method OnRender()
        c.Clear 0,0,255
        c.SetColor(1,1,1)
        c.DrawRect(x-width/2,y-height/2,width,height)
        c.SetScissor(x-width/2-margin,y-height/2-margin,width+margin*2,height+margin*2)
        c.Flush()
    End
End

The other issue is not a bug.
I run in html5 target, and I feel that the scissor is a bit late to update its location.
Scissor2.gif

As I move the box, the scissor is left a bit behind.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,298
The second problem is cause by you setting the scissor after you draw. You need. To set it before you draw.
 

magic

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
226
I redo. Same result.

I think something to do with this code in modules\mojo2\graphics.cxs
Code:
            If _scx<0 _scx=0 Else If _scx>_vpw _scx=_vpw
            If _scw<0 _scw=0 Else If _scx+_scw>_vpw _scw=_vpw-_scx
            
            If _scy<0 _scy=0 Else If _scy>_vph _scy=_vph
            If _sch<0 _sch=0 Else If _scy+_sch>_vph _sch=_vph-_scy

I change graphics.cxs to this and it work. But not settle the second issue. *Edit[second issue settle with SetScissor() on top covering Clear() command]
Code:
            If _scx<0 _scw+=_scx;_scx=0 Else If _scx>_vpw _scx=_vpw
            If _scw<0 _scw+=_scx;_scw=0 Else If _scx+_scw>_vpw _scw=_vpw-_scx
	
            If _scy<0 _sch+=_scy;_scy=0 Else If _scy>_vph _scy=_vph
            If _sch<0 _sch+=_scy;_sch=0 Else If _scy+_sch>_vph _sch=_vph-_scy
 
Last edited:

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,298
To me it isn't a bug. Scissors are only to effect the visible area. I think It is the developers responsibility.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,124
Edit[second issue settle with SetScissor() on top covering Clear() command]
Interesting! This makes everything synchronized again! I wonder if this applies to other instructions too, maybe SetMatrix etc. I will try a few things out this was very interesting.
 

magic

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
226
1.jpg


On case 1 : Everything Normal

On case 2 : Developer set scissor out of the screen. Mojo2 skip it. That OK

On case 3 : Developer set scissor partial of the screen. Mojo2 wants to cut the off-screen; Mojo2 alters X but ignores W. This is not good. (Current cerberus)

On case 4 : Expected result. Mojo2 cut the off-screen by cut the clip according to the visible area.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
686
This behaviour is definitely something to think about. But what you describe in case 3 is not a bug as far as I can see. You are saying it is not what the developer expects and that is what you expect in this example.
If you think about it from an objective perspective, with scissor you can specify a rectangle inside the viewport and in case 3 you are providing invalid values as the rectangle is not entirely inside the viewport. The question is more what to prioritize. You put position over size and the implementation seems to put size over position or in other words replace the invalid value y with the default of 0.
I will have a closer look at this in the next days and see what the OpenGL behaviour is and what the sideeffects might be.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,124
This got me thinking too but I'm pretty sure now that 3 is what you want becuase that is what happens to invalid max values. It should be symmetrical right? It also feels more intuitive when you code things like this. But googling shows that scissors is a devil in disguise.
 

SLotman

Active member
3rd Party Module Dev
Joined
Jul 3, 2017
Messages
191
SetScissor even in OpenGL works on "raw" screen coordinates. If you change resolution, it needs to be manually scaled.
And indeed, I *think* values are clamped to the visible area - long time since I coded anything related to this in plain OGL ;)

See this, the OpenGL command that does the same thing :)
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,298
It makes sense to update the logic of setscissor to make sure it takes into account when people falsely use it.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
686
Yes, I also thought about this. Maybe it could be checked if values are valid and give a warning otherwise. But I would only check if in debug mode and keep release code lean.
 
Top Bottom