• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Bug Scissor issue

mag

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
261
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.
 
The second problem is cause by you setting the scissor after you draw. You need. To set it before you draw.
 
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:
To me it isn't a bug. Scissors are only to effect the visible area. I think It is the developers responsibility.
 
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.
 
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.
 
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.
 
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.
 
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 :)
 
It makes sense to update the logic of setscissor to make sure it takes into account when people falsely use it.
 
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.
 
Back
Top Bottom