Skip to content

Lesson 1 Hello GhGL

Steve Baer edited this page Jan 3, 2019 · 8 revisions

GhGL consists of two components:

  1. GL Shader - a general purpose OpenGL shader component
  2. GL Mesh Shader - an OpenGL shader component with a mesh input to make it easier to work with meshes

This lesson will focus on the general purpose GL Shader component

1 - Drag a GL Shader component on to the canvas

By default, the component has two inputs labeled vertex and vcolor. Customizing the inputs will be covered in another lesson, so let's just leave everything as it is for now.

2 - Wire up the component inputs

Create a point component and a color component and wire them to the vertex and vcolor inputs. For the point component, set the data in the component to three points and set the color component to any color. Disable the preview for the point component so the points don't interfere with what the GL Shader component draws. If everything worked, you should see three dots on the screen where the point locations were specified (if you squint hard enough you can see three points in the above image.)

3 - Adjust how the input is interpreted

The right click context menu lets you set some OpenGL states for drawing. By default, the input was being drawn as GL_POINTSdraw mode. Change the draw mode to GL_LINE_LOOP and then to GL_TRIANGLES to see the difference in display for these different modes. This is the mode that is internally passed to the glDrawArrays function that occurs under the hood (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawArrays.xhtml)

Also, try changing the glPointSize value as well as the glLineWidth value. Make sure to have your draw mode set to GL_POINTS or GL_LINE_LOOP respectively when adjusting these sizes. It is probably obvious what these settings do, but in case you want more information you can learn about glPointSize and glLineWidth at

4 - Set multiple vertex colors

Set the component's draw mode to GL_TRIANGLES to display a triangle on the screen. Now adjust the color component to also have three output colors. The component should pick up on this and set each corner of the triangle to a different color with blending of colors in between.

That's it! Try experimenting by:

  • Setting alpha in one or more of the colors
  • Change the draw more to GL_LINE_LOOP or GL_LINE_LIST and change the line width
  • Add more than three points to the point component

Clone this wiki locally