Set buffer to ImageBuffer On Max2D

Started by Hardcoal, April 14, 2021, 14:25:10

Previous topic - Next topic

Hardcoal

I cant figure out how to draw on a TImage..
There is SetGraphics Command, but how to I change it to the Image to draw on it?

I mean without using Pixmap..

in blitz3D you do SetBuffer(ImageBuffer) and it works
Code

markcwm

There is no ImageBuffer in Blitzmax, don't really know why. You can either draw to a pixmap or draw to the BackBuffer and then "grab" the contents to an image, not sure but I think GrabImage will do it.

Pebender

Hi,
take a look here:

Import MaxGui.Drivers
'SuperStrict


Global GAME_WIDTH=320
Global GAME_HEIGHT=240

' create a centered window with client size GAME_WIDTH,GAME_HEIGHT

Local wx=(ClientWidth(Desktop())-GAME_WIDTH)/2
Local wy=(ClientHeight(Desktop())-GAME_HEIGHT)/2

Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,Null,WINDOW_TITLEBAR)'|WINDOW_CLIENTCOORDS)

' create a canvas for our game
Local canvas:TGadget=CreateCanvas(0,0,320,240,window)

' create an update timer

CreateTimer 60

While WaitEvent()
   Select EventID()
      Case EVENT_TIMERTICK
         RedrawGadget canvas

      Case EVENT_GADGETPAINT
         SetGraphics CanvasGraphics(canvas)
         SetOrigin 160,120
         SetLineWidth 5
         Cls
         Local t=MilliSecs()
         DrawLine 0,0,120*Cos(t),120*Sin(t)
         DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
         Flip

      Case EVENT_MOUSEMOVE
         Print "MOVE!"

      Case EVENT_WINDOWCLOSE
         FreeGadget canvas
         End

      Case EVENT_APPTERMINATE
         End
   End Select
Wend

you need Setgraphics() and a canvas, an you need Flip() to see the Image.

Hardcoal

Thanks.. I know CreateCanvas .. but im shocked there is no option to draw on an image..
i thought blitzmax was targeted well for 2D. yet.. even blitz3d has this option..

Thanks.. Ill experiment

Code

Henri

Hi,

there is a fundamental difference between the way Blitz3D and Blitzmax handle 2D graphics. Blitz3D uses the classical 2D approach with pixel data, but Blitzmax uses the so called 2D/3D approach where all the graphical objects are actually 3D objects internally, but look 2D because you are looking at a flat surface. Reason for this is probably due to benefits that come with handling 3D object: you can do rotating and scaling etc. essentially for free as this is done in graphics card and not with the cpu. Downside is that manipulation of indivial pixels is not that simple as is with the classical approach.

That been said, there is a way to render directly to a graphical object and that is renderToTexture function. There might be few of those floating around, but I believe col had one that should do the job. https://github.com/davecamp

-Henri

Disclaimer: I'm in no way an expert in this subject as I have not used Blitzmax graphical system to make a game as of yet (I did one in the original Blitzbasic for Amiga)
- Got 01100011 problems, but the bit ain't 00000001

Hardcoal

Now i understand. Thanks.
Ill try the example when im on pc and report..

👍🏻
Code

Derron

Maybe I wrote about it here already but

https://github.com/bmx-ng/brl.mod/pull/174
and
https://github.com/bmx-ng/sdl.mod/pull/26

would integrate col's render2texture into max2D.mod - yet it was not merged for almost a year now.

Col's approach requires adjustments to brl.mod too.


if you used "opengl" only then setting up a "render to texture" function is not too lengthy. Col's approach (and my little variant linked above) enables the same interface for opengl and irectx - so you do not need to care what to use. My version also extended it to properly support all backends brl.mod and sdl.mod offered for now.


bye
Ron

Hardcoal

Im trying to make a GUI.. so I chose doing the Buttons and Stuff using an Image

is that a Good Idea?

Thanks Derron BTW
Code

Pebender

Hi,
i´m making a GUI App too,
I´m using panels with Images on it for Buttons.
The Imagebutton in Bmax, is not so good an i´m using the GUI Designer from Logiczone, you can find the demo here in the board.
you can create your layout very fast.
My App im working on :



regards

Hardcoal

#9
Awesome thanks..

The reason im forced to make a gui is because i want to integrate  graphics with Gui.. like building a flowchart..

i just want to make a basic gui.. im not sure im gonna develop it to large extent.

i did a gui 10 years ago.. in blitz3d it worked fine..  but its hard work..
those days..
Code