Page 1 of 1

[NECTO Studio 2.1.0] gl_set_crop_borders doesn't work [solved]

Posted: 16 Sep 2022 10:57
by frank.malik
Hello,

made a small project on mikromedia 3 with PIC32MZ to test the gl_set_crop_borders function.

However, this doesn't work. Project attached.
Test_CropBorder.zip
(13.13 KiB) Downloaded 43 times

Code: Select all

    // Specify area on display for drawing.
    err_ret = gl_set_crop_borders(-1, -1, -1, -1); // Set hole display enabled because the area is invalid
    gl_draw_rect(50,50, 50, 50);         // Hole rect is visible

    // Specify area on display for drawing
    err_ret = gl_set_crop_borders(-5,-3, 75, 75); // Set borders for drawing on y=75 and x = 75 at right and bottom, while top and right borders are corrected to zeros.
    gl_draw_rect(65, 65, 50,50);          // Part of rect is cropped, and display has only rect between 50,50,75, 75

    // Specify area on display for drawing
    err_ret = gl_set_crop_borders(250,250, 300, 300); // Set borders for drawing between coordinates y=250 and y=300, x=250 and x=300
    gl_draw_rect(40, 40, 50,50);                 // Since rectangle does not appears in previously specified area, hole rect is not visible.
The code contains the commands to draw three rectangles, however, only one, the first one, should be
drawn completely. The second should be cropped and the third rectangle shouldn't be drawn at all.

In reality, all three rectangles are visible on the display.

Re: [NECTO Studio 2.1.0] gl_set_crop_borders doesn't work

Posted: 16 Sep 2022 13:29
by frank.malik
Hello again,

further tests show that in the end only one condition seems to fail:

Code: Select all

err_ret = gl_set_crop_borders(-5,-3, 75, 75);
This function returns with "true" and the borders are set to the display size ( 0, 0, 240, 320 )
Actually, according to the comment, it should only correct the minus values to zero, so that the borders are set like this ( 0, 0, 75, 75 )

This might be caused by the first if-clause in the gl.c file that checks the top and left values against the height resp the width. However,
the type of top is gl_coord_t, which is in fact int16_t, whereas the type of display_height is uint16_t. I think the comparison
of int16_t with uint16_t type variables might fail.

Code: Select all

    // If area is out of screen then set crop rect to screen's dimension
    if (top >= instance.driver.display_height
        || left >= instance.driver.display_width
        || right < 0
        || bottom < 0
        || bottom < top
        || right < left
    )
Using only positive numbers, except you want to reset the crop borders to the displays defaults, works as far as I could test so far.

Re: [NECTO Studio 2.1.0] gl_set_crop_borders doesn't work

Posted: 27 Oct 2022 10:14
by filip
Hi,

For cropping, please refer to the following code :

Code: Select all

// left crop
gl_set_crop_borders(27, 0, 52, 54);    

// top crop
// gl_set_crop_borders(0, 27, 52, 54);

// bottom crop
// gl_set_crop_borders(0, 0, 26, 54);    

// right crop
// gl_set_crop_borders(0, 0, 52, 27); 

// draw rectangle
gl_draw_rect(3, 1, 50,50);
The first line will crop the half of rectangle from the left border of the screen and the other similarly.

See the gl_set_crop_borders function explanation in the mikroSDK reference manual :
https://docs.mikroe.com/mikrosdk/ref-ma ... 66c1b0e243

As for the example code that you are referring to, I presume it some kind of left over from previous iterations, I'm sorry for the confusion.

Regards,
Filip.

Re: [NECTO Studio 2.1.0] gl_set_crop_borders doesn't work [solved]

Posted: 27 Oct 2022 20:08
by frank.malik
Hello Filip,

thanks for your reply, and the new example. No negative values seems to be ok for the gl_set_crop_borders function.