VIEWPORT bug with offscreen screens

Previous topic - Next topic

spacefractal

If I use offscreen screen, used with a "CREATESCREEN" command, then the cords is completly messed up and not working at all.

Here is the code I use for invoke the bug (a least on Windows):

Code (glbasic) Select

SETSCREEN 800, 600, 0
CREATESCREEN 2, 2, 200, 200

USESCREEN -1
DRAWRECT 0, 0, 200, 200, RGB(100, 0, 0)

USESCREEN 2 // view port dont like this screen and then messing the cords up completly.

//USESCREEN -1 <- doing this, VIEWPORT cords works, but... I can't use that in my case.
DRAWRECT 0, 0, 200, 200, RGB(200, 200, 200)
VIEWPORT 50, 50, 100, 100
DRAWRECT 0, 0, 100, 100, RGB(200, 0, 100) // this purple box, inside the gray box is gone, if USESCREEN 2 is used.
USESCREEN -1
DRAWSPRITE 2, 250, 250

SHOWSCREEN
KEYWAIT


The purple box is simply not draw at all, but should been drawed at the center of the gray box.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

I suspect VIEWPORT is only designed to work with the backscreen buffer...

Slydog

#2
Like MrTAToad said, it appears VIEWPORTs only work on the back buffer (-1).
And really they should, I can't quite wrap my head around how/why you would want a VIEWPORT on another screen.
[EDIT]: unless you are trying to show sprite/screen #2 inside a viewport on the main screen (-1).  If so the viewport should be set after the USESCReEN -1, but even then it would be pointing to another part of screen -1. 

Here's what I guess your code is doing:
- Set screen to '2'
- Draw a gray box 200x200
- Set a viewport 100x100 offset to position 50,50 showing back buffer
- On back buffer, draw a purple box 100x100 offset 50,50 because of viewport
- Switch back to back buffer
- Draw sprite 2 (just a 200x200 grey box) at position 250,250 in the viewport, which is offset 50,50 on screen, but outside of viewport visible range (only 50x50 pixels in size) so actually does nothing

I'm sure this is just a simplified example to show us your problem, as you could simply draw a purple rectangle inside of the grey one on screen 2 without using a viewport.

Could you give more detail of what you are trying to accomplish?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

spacefractal

#3
Yes it's just a simple show chase to show the issue. The gray and purple box is draw in screen 2, but viewport mess the cords up.

If you uncomment usescreen -1, then it's should have been that result with the purple box.

I is doing a lots of minigames section, where all graphics outside minigame area using back buffer. In screen 2 I draw all mini games graphics with full internal resoulution (i use two). When graphics drawn, it's simply scaling to the user mobile screen. This also make sure to avoid eventuelly seams in the mini games.

It's a clear bug, when not documented about it and should work with offscreen screens.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

VIEWPORTs on created screens could be used as a easy way of providing clipping and there could be good uses for it.

Whether or not VIEWPORTs will be updated to copy with created screens though is another matter :)

spacefractal

Yes it's extactly that I want, but cords not doing correctly.

Ps. Edited the above post to avoid eventuelly misunderstanding.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

ampos

On any created viewport, coordinates are relatives to this viewport windows. They are not messed. It is the way it is, and it is great.

Code (glbasic) Select
SETSCREEN 200,200,0
PLOT 50,50   <-this plot is drawn at coord 50,50 of main screen
VIEWPORT 50,50,50,50
PLOT 50,50 <-this plot is drawn at coord 50,50 of the viewport, that it is 100,100 of main screen.


It has many useful uses

MrTAToad

#7
Indeed, but its not working for created screens.

This is what it should look like, but you end up with the grey reactangle.  Which does make me think that viewports cant be used on created screens...  It will be up to Gernot to decide whether to allow it or not (assuming its not a bug :) )

[attachment deleted by admin]

spacefractal

#8
If viewport just clipped without any change to cords (etc x and y is allways as top left on the current USESCREEN), then it would been fine too.

I using screen 2 to draw a tiled map with alpha and more, but its placed wrong in all cords. Can't do that on back buffer at all.

PS. I forget a VIEWPORT 0,0,0,0 in the example (should placed just after the purple box), buts its does the same anyway.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello


Kitty Hello

Fixxxxored in next update/release.