1 (edited by HondaDirtBiker 2006-02-23 11:54:14)

Topic: Trouble drawing 2D image.

I need to draw a 2D Image for my HUD.
The code I tried gives me the error "Expecting ')' but encountered '.' at character 79".

The code I tried is

Global weapon:T_IrrIVideo.draw2DImage (video, weaponimage, T_irrPosition2d_s32.createFromVals(400, 64))

Re: Trouble drawing 2D image.

greetings smile  you need an instance of the videodriver.  try the following:

driver.draw2DImage (weaponimage, T_irrPosition2d_s32.createFromVals(400, 64))

where driver is an instance of T_irrIVideoDriver.  the videodriver instance can be obtained by calling getVideoDriver() on the instance of T_irrIrrlichtDevice.

Re: Trouble drawing 2D image.

I still can't make it work. I tried all diferent ways of writing the code.
I'm guess I still don't understand Irrlicht very well. sorry.

Re: Trouble drawing 2D image.

thats ok smile  im going to create an example tonight for vextrex and ill whip up some sample code for you as well.  could you post a complete sample of what you are trying?

thx.

Re: Trouble drawing 2D image.

Sure, Thanks.

'===============================================
'--------------- Player HUD Test ---------------
'===============================================

' *!* make sure you build this example with the "Build GUI App" option turned off

Strict
Framework BRL.Blitz
Import BRL.StandardIO

Import gg.IrrBMAX

'===============================================
'---------------- Player Input -----------------
'===============================================

'===============================================
'---------------- Irrlicht GUI -----------------
'===============================================

' due to OnEvent implementation, these must be global

Global cnt:Int = 0
Global listbox:T_irrIGUIListBox

Type MyEventReceiver Extends T_irrIEventReceiver

    Method OnEvent:Int(event:T_irrSEvent)

        If (event.getEventType()=EET_GUI_EVENT)

            Local id:Int = event.getGUIEventCaller().getID()
            Local gui:T_irrIGUIEnvironment = device.getGUIEnvironment()

            Local evtype:Int=event.getGUIEventType()

            Select evtype
                Rem
                If a scrollbar changed its scroll position, And it is 'our'
                scrollbar (the one with id 104), Then we change the
                transparency of all gui elements. This is a very easy task:
                There is a skin Object, in which all color settings are stored.
                We simply go through all colors stored in the skin And change
                their alpha value.
                EndRem

                Case EGET_SCROLL_BAR_CHANGED
                    If (id = 104)
                        Local pos:Int = T_irrIGUIScrollBar.createFromHandle(event.getGUIEventCaller().handle,False).getPos()
                        Local i:Int

                        For i=0 To EGDC_COUNT-1
                            Local col:T_irrSColor = gui.getSkin().GetColor(i)
                            col.setAlpha(pos)
                            gui.getSkin().SetColor(i,col)
                        Next
                    EndIf

                Rem
                If a button was clicked, it could be one of 'our'
                three buttons. If it is the first, we shut down the engine.
                If it is the second, we create a little window with some
                text on it. We also add a String To the list box To Log
                what happened. And If it is the third button, we create
                a file open dialog, And add also this as String To the list box.
                That's all for the event receiver.
                EndRem

                Case EGET_BUTTON_CLICKED

                    If (id = 103)
                        device.closeDevice()
                        Return True
                    EndIf

                    If (id = 102)
                        listbox.addItem("Window created")
                        cnt :+ 30
                        If (cnt > 200)
                            cnt = 0
                        EndIf

                        Local window:T_irrIGUIWindow = gui.addWindow( ..
                            T_irrRect_s32.createFromVals(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt), ..
                            False, .. ' modal?
                            "Test window")

                        gui.addStaticText("Please close me", ..
                            T_irrRect_s32.createFromVals(35,35,140,50), ..
                            True, .. ' border?
                            False, .. ' wordwrap?
                            window)

                        Return True
                    EndIf

                    If (id = 101)
                        listbox.addItem("File open");
                        gui.addFileOpenDialog("Please choose a file.")
                        Return True
                    EndIf
            EndSelect
        EndIf

        Return False
    EndMethod

    ' we must override the generate function in order for instantiation to work properly
    ' must return T_irrIEventReceiver
    Function generate:T_irrIEventReceiver()
        Return T_irrIEventReceiver(New MyEventReceiver)
    EndFunction
EndType

'===============================================
'---------------- Engine Set Up ----------------
'===============================================

Rem
    The Next few lines start up the engine. Just like in most other tutorials
    before. But in addition, we ask the user If he wants this example To use
    high level shaders If he selected a driver which is capable of doing so.
EndRem

Rem
Select driver Type

EDT_SOFTWARE, EDT_SOFTWARE2, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, EDT_OPENGL.
EndRem

' create device
Global device:T_irrIrrlichtDevice=T_irrIrrlichtDevice.create(EDT_DIRECT3D8,T_irrDimension2d_s32.create(1024,768),16,True,False,True,Null)

If device.handle=0 Then Return ' could Not create selected driver.
Local video:T_irrIVideoDriver=device.getVideoDriver()
Local scene:T_irrISceneManager=device.getSceneManager()
Local gui:T_irrIGUIEnvironment=device.getGUIEnvironment()

'===============================================
'------------------ Main Menu ------------------
'===============================================

Rem
We add three buttons. The first one closes the engine. The second
creates a window And the third opens a file open dialog. The third
parameter is the id of the button, with which we can easily identify
the button in the event receiver.
EndRem

gui.addButton(T_irrRect_s32.createFromVals(10,210,100,240), Null, 101, "File Open")
gui.addButton(T_irrRect_s32.createFromVals(10,250,100,290), Null, 102, "New Window")
gui.addButton(T_irrRect_s32.createFromVals(10,300,100,340), Null, 103, "Quit")

Rem
Now, we add a static text And a scrollbar, which modifies the
transparency of all gui elements. We set the maximum value of
the scrollbar To 255, because that's the maximal value for
a color value.
Then we create an other static text And a list box.
EndRem

gui.addStaticText("Transparent Control:", T_irrRect_s32.createFromVals(150,20,350,40), True)
Local scrollbar:T_irrIGUIScrollBar = gui.addScrollBar(True, T_irrRect_s32.createFromVals(150, 45, 350, 60), Null, 104)
scrollbar.setMax(255)

gui.addStaticText("Console:", T_irrRect_s32.createFromVals(50,80,250,100), True)
listbox = gui.addListBox(T_irrRect_s32.createFromVals(50, 110, 250, 180))

Rem
To make the font a little bit nicer, we load an external font
And set it as New font in the skin. An at last, we create a
nice Irrlicht Engine logo in the top Left corner.
EndRem

Local skin:T_irrIGUISkin = gui.getSkin()
Local font:T_irrIGUIFont = gui.getFont("media/fonthaettenschweiler.bmp")
If (font.isValid())
    skin.setFont(font)
EndIf

'===============================================
'------------------ Player HUD -----------------
'===============================================

Global weapon:T_IrrIVideoDriver = video.draw2DImage (video, weaponimage, T_irrPosition2d_s32.createFromVals(400, 64))
Local weaponimage = video.addTexture ("media/machine gun.bmp")

'===============================================
'----------------- Scene Props -----------------
'===============================================

'===============================================
'----------------- Scene Setup -----------------
'===============================================

Rem
And last, we add a skybox And a user controlled camera To the scene.
For the skybox textures, we disable mipmap generation, because we don't
need mipmaps on it.
EndRem

' add a nice skybox

scene.addSkyBoxSceneNode( ..
    video.getTexture("media/Galaxy_UP.bmp"), ..
    video.getTexture("media/Galaxy_DN.bmp"), ..
    video.getTexture("media/Galaxy_LT.bmp"), ..
    video.getTexture("media/Galaxy_RT.bmp"), ..
    video.getTexture("media/Galaxy_FT.bmp"), ..
    video.getTexture("media/Galaxy_BK.bmp"))

video.setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, False)
video.setTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED, True)

Rem
We create a Mesh Viewer style camera and make the
mouse cursor visible.
EndRem

Local cam:T_irrICameraSceneNode = scene.addCameraSceneNodeMaya(Null, 100.0, 100.0)
cam.setPosition(T_irrVector3df.createFromVals(-100,50,100))
cam.setTarget(T_irrVector3df.createFromVals(0,0,0))
device.getCursorControl().setVisible(True)

Local lastFPS:Int = -1
Local fps:Int = 0
Local str:String=""

'===============================================
'---------------- Render Scene -----------------
'===============================================

While(device.run())
    If (device.isWindowActive())
    device.setEventReceiver(T_irrIEventReceiver.create(MyEventReceiver.generate))

        video.beginScene(True, True, T_irrSColor.createFromVals(255,0,0,0))

        scene.drawAll()
        gui.drawAll()
        video.endScene()

        fps = video.getFPS()

        If (lastFPS <> fps) Then
            str$ = "HUD Test - Irrlicht ["
            str$ :+ video.getName()
            str$ :+ "] FPS:"
            str$ :+ fps

            device.setWindowCaption(str$)
            lastFPS = fps
        EndIf

    EndIf

    'FlushMem
Wend

Re: Trouble drawing 2D image.

i think you are very close.  change the following lines:

Global weapon:T_IrrIVideoDriver = video.draw2DImage (video, weaponimage, T_irrPosition2d_s32.createFromVals(400, 64))
Local weaponimage = video.addTexture ("media/machine gun.bmp")

to

Local weaponimage:T_irrITexture = video.getTexture ("media/machine gun.bmp")
video.draw2DImage (weaponimage, T_irrPosition2d_s32.create(400, 64))

HTH

Re: Trouble drawing 2D image.

Thank you very much.
I acctually tested this code and it would'nt show the image. Then, I noticed from an irrlicht sample, the draw2d function was placed inbetween "drawall" and "endscene" of the "device.run" call.

While(device.run())
    If (device.isWindowActive())
    device.setEventReceiver(T_irrIEventReceiver.create(MyEventReceiver.generate))

        video.beginScene(True, True, T_irrSColor.createFromVals(255,0,0,0))

        scene.drawAll()
        gui.drawAll()

'        add draw 2d image command here.

        video.endScene()

    EndIf

    'FlushMem
Wend

Just in case someone runs into this.

Re: Trouble drawing 2D image.

very interesting Honda thank you.  i didnt realize it either but the drawing of 2D is not within the confines of GUI or Scene so it does make sense that it would need to be drawn in the loop.