Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ClearWindows & ClearVG: LWJGL3 Windowing and GUI Solution  (Read 471 times)
0 Members and 1 Guest are viewing this topic.
Offline SkyAphid
« Posted 2019-04-21 23:47:45 »

Hello everyone. I recently had the fantastic opportunity to work with Orange451 on his LWJGL3 GUI solution, LWJGUI. I was able to not only contribute some cool new tools to it, but also learn a lot about UI tool creation and NanoVG. While originally I was going to use this solution to create my program ClearDialogue, I realized very early in that what I needed was something a bit more barebones because I was trying to force his API to work with a program that was much simpler in nature than what it's designed to normally handle (complex programs that require many moving parts to function). Thus, I decided to start the Clear project, which is an API meant to work in modular pieces and give a lot of flexibility to the user-interface creation process by having less moving parts.


Github Repository Link:
https://github.com/SkyAphid/Clear

What is Clear?
Clear is a light-weight open source LWJGL3 toolkit split into two pieces:
  • ClearWindows - a simple LWJGL3 windowing solution that allows you to quickly create a GLFW window with OpenGL capabilities, along with a basic framework for making applications/games quickly
  • ClearVG - an extension of ClearWindows that allows you to add NanoVG support to your ClearWindow implementation, along with some basic tools for UI creation and custom-extensions

This means that fundamentally, Clear is slightly more complicated to use than LWJGUI and requires much more time to get started with. If you're looking for a framework that has a lot of functionality already built in, Clear is not for you. I highly recommend the use of LWJGUI in cases like this, as it's feature rich and actively maintained by a very talented developer.

What is the use-case for Clear?
Clear offers the ability to have a stable framework to start from when creating any kind of application. ClearWindows can be used for game creation because it allows you to quickly set up a GLFW window along with all of the required input callbacks, gameplay loops, timers, and lastly, OpenGL integration. On the other hand, the toolset also contains ClearVG, which adds rendering functionality that can be beneficial for creating extremely custom user-interfaces by only including the most barebones features by default. There is only one UI coordinate system, and layout systems of any kind must be added manually by the user outside of the included WidgetAssembly system (see the example programs to learn more). Components such as buttons must be assembled manually as well, but this allows the user to create the program to work in any fashion that they like.

It's important to note that while these systems are barebones, they're also designed from the ground-up to be fast and reliable to use - meaning that while you do have to build a lot of the features you'll want yourself, it's been designed so that this can be done extremely fast and painlessly.

I've had all this working for about a month now and have done some extensive testing, but there may still be some hiccups here and there once it's out in the wild. Let me know if you run into any issues or need help using these tools! I hope it's helpful to some of you guys! Especially if you're a newcomer to LWJGL3, this may help you get started with using it!

Code of the above Hello World program in its entirety:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
public class ClearHelloWorldDemo extends ClearApp {

   private static final int WINDOW_WIDTH = 256;
   private static final int WINDOW_HEIGHT = 256;
   
   protected WidgetAssembly button;
   protected Font font;
   
   public static void main(String[] args) {
      ClearApp.launch(new ClearHelloWorldDemo(), args);
   }

   @Override
   public void init(WindowManager windowManager, Window window, NanoVGContext context, WidgetAssembly rootWidgetAssembly, String[] args) {
     
      /*
       * WidgetAssembly (containers for various widgets)
       */

     
      button = new WidgetAssembly(100, 50, new WidgetClip(WidgetClip.Alignment.CENTER));
     
      /*
       * Background - rectangle with dropshadow
       */

     
      float cornerRadius = 3f;
     
      button.addChild(new DropShadowWidget(cornerRadius));
      button.addChild(new RectangleWidget(cornerRadius, ClearColor.CORAL, true));
     
      /*
       * Text
       */

     
      try {
         font = new Font("fonts/NotoSans/", "NotoSans-Regular", "NotoSans-Bold", "NotoSans-Italic", "NotoSans-Light").load(context);
         
         LabelWidget label = new LabelWidget(ClearColor.WHITE_SMOKE, "Hello World!", font, FontStyle.REGULAR, 20);
         label.addChild(new WidgetClip(WidgetClip.Alignment.CENTER));
         button.addChild(label);
      } catch (IOException e1) {
         e1.printStackTrace();
      }
     
      /*
       * Input - click the WidgetAssembly to toggle rendering and show the bounding
       */

     
      button.setOnMouseMotionEvent(e -> {
         if (button.isMouseIntersectingThisWidget(window)) {
            ClearStaticResources.getCursor(Cursor.Type.HAND).apply(window);
         } else {
            ClearStaticResources.getCursor(Cursor.Type.ARROW).apply(window);
         }
      });
     
      button.setOnMouseButtonEvent(e -> {
         if (e.isPressed() && button.isMouseIntersectingThisWidget(e.getWindow())) {
            button.setBackgroundFill(button.getBackgroundFill() != null ? null : ClearColor.LIGHT_GRAY);
            button.setRenderChildren(!button.isRenderingChildren());
         }
      });
     
      /*
       * Add button to root assembly
       */

     
      rootWidgetAssembly.addChild(button);
   }


   @Override
   protected void endOfNanoVGApplicationCallback() {
     
   }

   @Override
   public Window createWindow(WindowManager windowManager) throws GLFWException {
      return windowManager.createWindow("Clear", WINDOW_WIDTH, WINDOW_HEIGHT, true, true);
   }

}


Screenshots of example programs made with Clear:

Code Area Example


Input Sub-Window Example


Projects developed entirely with ClearWindows and ClearVG:

ClearDialogue - branching video game dialogue solution (Click me!)


it just werks
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (2633 views)
2018-11-16 13:46:03

hadezbladez (952 views)
2018-11-16 13:41:33

hadezbladez (2592 views)
2018-11-16 13:35:35

hadezbladez (512 views)
2018-11-16 13:32:03

EgonOlsen (3746 views)
2018-06-10 19:43:48

EgonOlsen (4142 views)
2018-06-10 19:43:44

EgonOlsen (2498 views)
2018-06-10 19:43:20

DesertCoockie (3306 views)
2018-05-13 18:23:11

nelsongames (3402 views)
2018-04-24 18:15:36

nelsongames (4380 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!