@@ -35,6 +35,7 @@ RLOrderBookVis::RLOrderBookVis(Rectangle aBounds, size_t aHistoryLength, size_t
3535RLOrderBookVis::~RLOrderBookVis () {
3636 cleanupTexture ();
3737 cleanupMesh ();
38+ cleanupRenderTarget ();
3839}
3940
4041void RLOrderBookVis::cleanupTexture () {
@@ -59,6 +60,33 @@ void RLOrderBookVis::cleanupMesh() {
5960 }
6061}
6162
63+ void RLOrderBookVis::cleanupRenderTarget () const {
64+ if (mRenderTargetValid && mRenderTarget .id != 0 ) {
65+ UnloadRenderTexture (mRenderTarget );
66+ mRenderTarget = RenderTexture2D{};
67+ mRenderTargetValid = false ;
68+ mRenderTargetWidth = 0 ;
69+ mRenderTargetHeight = 0 ;
70+ }
71+ }
72+
73+ void RLOrderBookVis::ensureRenderTarget () const {
74+ int lWidth = (int )mBounds .width ;
75+ int lHeight = (int )mBounds .height ;
76+
77+ // Recreate if dimensions changed or not valid
78+ if (mRenderTargetValid && (mRenderTargetWidth != lWidth || mRenderTargetHeight != lHeight)) {
79+ cleanupRenderTarget ();
80+ }
81+
82+ if (!mRenderTargetValid || mRenderTarget .id == 0 ) {
83+ mRenderTarget = LoadRenderTexture (lWidth, lHeight);
84+ mRenderTargetValid = (mRenderTarget .id != 0 );
85+ mRenderTargetWidth = lWidth;
86+ mRenderTargetHeight = lHeight;
87+ }
88+ }
89+
6290void RLOrderBookVis::setBounds (Rectangle aBounds) {
6391 mBounds = aBounds;
6492}
@@ -770,6 +798,16 @@ void RLOrderBookVis::draw3D(const Camera3D& rCamera) const {
770798 return ;
771799 }
772800
801+ // Ensure render target exists and matches bounds dimensions
802+ ensureRenderTarget ();
803+ if (!mRenderTargetValid || mRenderTarget .id == 0 ) {
804+ return ;
805+ }
806+
807+ // Render 3D scene to offscreen texture
808+ BeginTextureMode (mRenderTarget );
809+ ClearBackground (mStyle .mBackground );
810+
773811 BeginMode3D (rCamera);
774812
775813 // Center the mesh
@@ -809,5 +847,17 @@ void RLOrderBookVis::draw3D(const Camera3D& rCamera) const {
809847 DrawMesh (mAskMesh , lMat, lTransform);
810848
811849 EndMode3D ();
850+ EndTextureMode ();
851+
852+ // Draw the render texture at the bounds position
853+ // Note: RenderTexture Y is flipped, so we use negative height in source rect
854+ const Rectangle lSrc = {0 , 0 , (float )mRenderTargetWidth , -(float )mRenderTargetHeight };
855+ const Rectangle lDst = {mBounds .x , mBounds .y , mBounds .width , mBounds .height };
856+ DrawTexturePro (mRenderTarget .texture , lSrc, lDst, Vector2{0 , 0 }, 0 .0f , WHITE);
857+
858+ // Draw border on top if enabled
859+ if (mStyle .mShowBorder ) {
860+ DrawRectangleLinesEx (mBounds , mStyle .mBorderThickness , mStyle .mBorderColor );
861+ }
812862}
813863
0 commit comments