SDK Question2D panel drawing

Observation

New member
Hi,
I'm running into some trouble redrawing 2D panels.
I tried to create a custom texture adapted to the viewport (1 surface pixel = 1 screen pixel).
The surface is created like this:
PHP:
panel_surface = oapiCreateSurfaceEx(panel_surfaceWidth, panel_surfaceHeight,
OAPISURFACE_TEXTURE | OAPISURFACE_RENDERTARGET);
with panel_surfaceWidth and panel_surfaceHeight being the texture width and height.
I'm already unsure if those flags are correct. Is OAPISURFACE_TEXTURE necessary for 2D panels? What does OAPISURFACE_RENDERTARGET actually do?

My background texture is set like this:
PHP:
panel_vessel->SetPanelBackground(hPanel, &panel_surface, 1, panel_mesh,
PANEL_WIDTH, PANEL_HEIGHT, 0,
PANEL_ATTACH_BOTTOM | PANEL_MOVEOUT_BOTTOM);
with PANEL_WIDTH and PANEL_HEIGHT being the logical mesh boundaries.

And finally, my area registration is done with the VESSEL4 class interface:
PHP:
panel_vessel->RegisterPanelArea(hPanel, PANEL_LEGS.id, PANEL_LEGS.tgt,
0, PANEL_LEGS.propTgt(panel_surfaceWidth, panel_surfaceHeight),
PANEL_MOUSE_IGNORE, PANEL_MAP_NONE);
where .tgt is my logical target rectangle and propTgt() returns the target rectangle in texture coordinates.

It seems to turn out that the surface passed to clbkPanelRedrawEvent() corresponds to the pos parameter of RegisterPanelArea, not texpos. That means the texture is not the right size and isn't blitted in the right place.

So I tried to replace PANEL_MAP_NONE with PANEL_MAP_DIRECT. Unfortunately, the surface recieved by clbkPanelRedrawEvent() is NULL, and Orbiter crashes when leaving the 2D panel view or exiting (before my cleanup functions are called).

Then I tried to ignore the surf parameter that is recieved and just blit everything directly onto my surface I keep as a class attribute. But maybe that's not quite the right way to do it, considering I still have to deal either with a crash at the end or an unwanted black rectangle in the middle of my panel.

Does someone have any insight into this ?

News Reporter
Donator

Observation

New member
I did not in fact. Thank you for it.
I'm specifically having trouble with textures of different (and variable) size. I'll give it a try with mesh modification, see how that goes.
To my understanding, redraw surfaces are blitted directly on the surface provided to RegisterPanelArea. Is that right? Also, is the panel automatically redrawn at each frame or is there a specific function to call for this ?

Notebook

News Reporter
Donator
I'm afraid I can't help you with those questions, hopefully folk here can.

I followed along with that tutorial at the time, but I never really understood the concepts.
Went back to making bases!

Observation

New member
Haha fair enough.
So I tried implementing those animations through mesh modifications, but I couldn't find a method to redraw the panel (or only a specific mesh group), so my screen is static. Unfortunately, Martin's masterclass ended right when he was going to explain that. But he was talking about this, so it must be possible somehow.

News Reporter
Donator

asbjos

tuanibrO
Haha fair enough.
So I tried implementing those animations through mesh modifications, but I couldn't find a method to redraw the panel (or only a specific mesh group), so my screen is static. Unfortunately, Martin's masterclass ended right when he was going to explain that. But he was talking about this, so it must be possible somehow.

I had the same frustration myself. So I can't see to make an animated panel either.

You could try looking into the DG/ShuttleA source code. I tried it myself, but all the hundreds of different functions and classes made it too cluttered for me. Maybe you will understand it better.

Observation

New member
So I had a look I had a look into the DG code and it turns out that it was very similar to what I had written. Just modify the panel mesh with either oapiMeshGroup() or oapiEditMeshGroup() (I didn't actually understand where the difference is, apparently the latter is better), and the rest is magic. Turns out I had some other errors in my code that made it skip the animation :facepalm: .
Now I have a working landing legs animation!!

But I would keep on a side note that VESSEL4::RegisterPanelArea() makes Orbiter pass a SURFHANDLE the size of pos, not texpos to clbkPanelRedrawEvent...

llarian

Well-known member
When you guys sort it all out, how about posting a tutorial on the subject?

Observation

New member
When you guys sort it all out, how about posting a tutorial on the subject?
Sure! It might be a while until I get to that point though.

As I understand it, the panel is rerendered at each frame anyways. So I think that the mesh modification method is actually faster than the clbkPanelRedrawEvent method: no need to have uncompressed surfaces, no blitting, and I'm also wondering how Orbiter handled the case of a panel area being on two mesh groups in past implementations (VESSEL2)(edit: nevermind, VESSEL2::RegisterPanelArea() doesn't exist anyway). Martin gives it the disadvantage of a complexified mesh. Does that have a significant performance impact?

Regarding performance, I was wondering how much of a performance improvement we can have if we adapt the texture once vs letting the GC do it when rendering. Is that a sensible thing to do, since the GC does it all the time anyways?

Of course, for elements like MFD buttons or the like, for which we have to create the content at run time, we still need uncompressed textures. For drawing unto those, the best thing to use is the Sketchpad, if I'm not mistaken? Then, is there an advantage to use the clbkPanelRedrawEvent function rather than drawing directly onto the surface?

Last edited:

Replies
7
Views
436
Replies
11
Views
1K
Replies
1
Views
498
Replies
10
Views
1K