0

I am trying to create a hexagon on the screen in my LWJGL game. I am using Nifty GUI. I currently have 2 screens, and I want to switch to a screen where I programmatically draw hexagons.

Here is my xml for the screen

<?xml version="1.0" encoding="UTF-8"?>

<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="start" controller="StartScreen">
    <layer id="background" childLayout="center">
        <image filename="util/img/menuTexture.png" />
    </layer>
    <layer id="title" childLayout="vertical">
        <image align="center" height="20%" width="80%" filename="util/img/title.png" />
        <panel id="subactions" childLayout="absolute" marginTop="40%" height="13%">
            <image align="left" height="100%" width="30%" x="0px" y="0px" filename="util/img/rules.png">
                <interact onClick="showRules()" />
            </image>
            <image align="right" height="100%" width="30%" x="70%" y="0px" filename="util/img/exit.png">
                <interact onClick="exitGame()" />
            </image>
        </panel>
        <image align="center" height="20%" width="80%" filename="util/img/start game.png" marginTop="5%">
            <interact onClick="startGame()" />
        </image>
    </layer>
</screen>
<screen id="rules" controller="StartScreen">
    <layer id="background" childLayout="center">
        <image filename="util/img/menuTexture.png" />
    </layer>
    <layer id="transparent" backgroundColor="#D1D1D1A7" childLayout="vertical">
        <panel id="rulesPanel" childLayout="center">
            <image filename="util/img/game rules.png" width="100%" height="100%" />
        </panel>
        <panel id="goToStartPanel" childLayout="center" width="100%" height="13%">
            <image height="100%" filename="util/img/exit.png">
                <interact onClick="goToStartScreen()" />
            </image>
        </panel>
    </layer>
</screen>

How do I switch to such a screen (would I use nifty.gotoScreen() ?) and initialize the render loop?

Any example code would be helpful. Thank you very much.

Jay S.
  • 1,318
  • 11
  • 29

1 Answers1

0

Yes, you always use nifty.gotoScreen() to switch to a different screen.

But I don't really understand the drawing shapes part ;) Current Nifty, 1.3.x or 1.4.x don't support custom drawing to a screen. But no one prevents you to render other things before or after you call nifty.render() which makes things appear below or above the elements rendered by Nifty.

If you want to have some elements directly on the Nifty screen custom drawn by you your only chance would be to get hold of a texture that Nifty renders and render to that texture on your own (outside and without any help from Nifty). Nifty will just display the texture as an image element for instance but you could have change the content of the texture outside of Nifty.

Does that make sense?

void256
  • 1,286
  • 10
  • 11
  • Yeah that makes sense. Could you maybe point me to some example code on how to get hold of the texture and render with lwjgl. I know how to use nifty and lwjgl separately, but not together. Thanks! @void256 – Jay S. Apr 08 '15 at 20:54
  • I don't have any example code available for this, unfortunately. Additionally this depens on the Nifty version you're using and what LWJGL renderer you're on (classic, batched, core profile batched etc.). What you need to do is to get access to the RenderImage instance, cast it to specific impl you're using and access its OpenGL textureId. Use this to access the texture from LWJGL to modify it and then call f.i. https://github.com/void256/nifty-gui/blob/1.4/nifty-core/src/main/java/de/lessvoid/nifty/render/NiftyImage.java#L133 after you modified the texture. Sorry that there is no easier way. – void256 Apr 09 '15 at 20:31