Jump to content

2D Image rendering


mdidillon
 Share

Recommended Posts

Hello,

 

i am currently working on 2D GUI for my game and i have some questions about the given 2D render function of the leadwerks engine.

With the given c/c++ 2D render function (DrawText, DrawImage, etc.):

 

Is it possible to set a clipping rectangle?

Is there a way to draw a image with a source and destination rectangle?

 

marc

 

PS: The attached screenshot shows the current state of the implementation

post-495-12651336968851_thumb.jpg

Link to comment
Share on other sites

Is it possible to set a clipping rectangle?
You need to render to a smaller buffer and display the buffer either as 3D texture or also with DrawImage.

 

Is there a way to draw a image with a source and destination rectangle?
You can scale the image using it's height and width parameters.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

  • 2 years later...

Since I'm also creating my own GUI code using just Leadwerks commands, I've run into the same problem. Using the advice above and my own shaky understanding of Leadwerks' buffer commands, I've come up with the following:

 

// initialization before rendering loop
int viewportWidth = 177;
int viewportHeight = 12;
TTexture viewportTexture = CreateTexture( viewportWidth, viewportHeight );
ClampTexture( viewportTexture );
TBuffer viewportBuffer = CreateBuffer( viewportWidth, viewportHeight );
// inside the rendering loop
TBuffer previousBuffer = CurrentBuffer();
SetColorBuffer( viewportBuffer, viewportTexture );
SetBuffer( viewportBuffer );
ClearBuffer();
DrawText( 0, 0, "This is a test of view port clipping." );
TTexture tempTexture = GetColorBuffer( viewportBuffer );
SetBuffer( previousBuffer );
DrawImage( tempTexture, 0, 0, viewportWidth, -viewportHeight );

 

It seems to work correctly. One oddity is I had to make the height parameter, for the last DrawImage command, a negative value or it would draw the texture upside down. Not sure why that happens.

 

Anyways, I was wondering if this is the method I should use. Is it prone to any bugs? Is there a more efficient method I should be using?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...