How to Draw a Simple Line

If you need to draw few lines with GeeXLab, this article should help you.

There is no line object in GeeXLab. But fortunately, there is a powerful object called polyline. A polyline is usually used to draw a ton of lines but can be used to draw a single line as well.

Here is the code to create a line made up of two vertices:

line = gh_polyline.create_v2(2, 0)

 
Now you can set the position of the line vertices (in the INIT or FRAME scripts):

gh_polyline.set_vertex_position(line, 0, -4, -4, 0, 1)
gh_polyline.set_vertex_position(line, 1, 4, 4, 0, 1)

 
You can also use all object functions to set the transformation of the line (position, rotation, scale): gh_object.set_position(), gh_object.set_euler_angles(), gh_object.set_scale().


How to draw lines with GeeXLab

 
Here is the FRAME script used to render the previous image:

gh_camera.set_position(camera, 0, 0, 10)
gh_camera.set_lookat(camera, 0, 0, 0, 1)
gh_camera.bind(camera)

gh_renderer.clear_color_depth_buffers(0.2, 0.2, 0.2, 1.0, 1.0)

gh_gpu_program.bind(color_prog)

-- The RED line
gh_gpu_program.uniform4f(color_prog, "color", 1, 0, 0, 1)
gh_polyline.set_vertex_position(line, 0, -4, -4, 0, 1)
gh_polyline.set_vertex_position(line, 1, 4, 4, 0, 1)
gh_object.render(line)

-- The GREEN line
gh_gpu_program.uniform4f(color_prog, "color", 0, 1, 0, 1)
gh_polyline.set_vertex_position(line, 0, -2, -4, 0, 1)
gh_polyline.set_vertex_position(line, 1, 4, 0, 0, 1)
gh_object.render(line)

 
A demo is available in the host_api/Line/ folder of the code sample pack.





Leave a Comment

Your email address will not be published. Required fields are marked *