Programming Code Samples

especially in
C and C++
for
GUI and 3D apps
on Linux


GLUI widgets
GLUI is a utility-extension of OpenGL
to provide basic GUI building capability

Home page > RefInfo menu >

Computer Topics menu >

'Linux Guides of Others' menu page >

This Programming Code Samples (C and C++, GUI and 3D) page

! Note !
More code samples may be added ---
if I ever use this page much.
(Not likely, cause I have many Tcl-Tk projects.)

Most of these examples are code that
is to be compiled into binary objects.
Some compile scripts (and even binaries)
could be provided here, if compilations
of any of these code samples are done
(on Linux) in following months/years.

< Go to start of Table of Contents, below. >
(Skip the Introduction)

INTRODUCTION :

The intention of this page is to provide complete code examples, to help me learn programming in C (or C++) --- using OpenGL on 3D data --- and using GUI library routines from GLUT, GLUI, FLTK, GTK, wxWidgets, Qt, Tcl-Tk, or other GUI-making systems.

    Alternatively, I may stick with Tcl-Tk programming and use these 'compiled language' code samples as sources of useful routines that can be re-coded into Tcl-Tk routines.

I taught myself Tcl-Tk script programming (in the late 1990's) --- after learning FORTRAN programming (in the 1960's), COBOL programming (in the 1970's), APL programming (in the 1980's), and Unix shell programming (in the early 1990's) --- all through self-training and on-the-job training (not classroom, except for a few less-than-one-week training sessions).

In the process of learning Unix shell scripting and Tcl-Tk scripting, I found the best way to learn is to try to do complete code examples as soon as possible --- like the classic 'Hello World' program. And then proceed quickly on to additional complete (and useful) code examples, using simple complete code examples to start with.

Even when I was looking for working (de-bugged) code snippets, I usually found the best ones within complete code samples.

So I was often doing web searches for code samples containing a string like '/bin/sh' or '/bin/wish', since that was usually a sign of a complete 'script' code example (a complete mini-application) --- starting with a line like '#!/bin/sh' or '#!/usr/bin/wish' or '#!/usr/local/bin/wish'.

I find that tutorials and books that are made up completely of code 'snippets' are not nearly as useful as tutorials and books that start off with a 'hello world'-type example and build up to making at least one complete code project --- such as a working file browser or a working game program (even if they are somewhat lacking, and leave some details to be finished later, by the reader).

So with that background, I collected the examples which are itemized in the following 'Table of Contents' (actually a 'Table of Links').

I can access these examples from any of my computers --- desktops at home and netbooks/laptops at home or away from home. (A little 'light reading' when 'on the road'.)

Many of the examples below are OpenGL demo programs, from SGI staff members, back in the early to mid 1990's --- or they are programs based on those early demo programs.

Most of these code samples show how to handle various kinds of keyboard and mouse input. And many examples include code to make GUI's --- using GLUT (basic) or GLUI (a little fancier) or FLTK (still fancier) or even fancier --- using GTK or Qt or wxWidgets.

For more information on how to use this page, see the comments below the Table of Contents.

TABLE OF CONTENTS :

(Links to sections, below, on this page.)

End of Table of Contents.

See the code presentation notes below.

HOW THE CODE SAMPLES (BELOW) ARE PRESENTED - and other notes :

Each of these code samples is presented as an HTML embedded plain-text 'object' so that you can scroll the text of each code sample, vertically or horizontally, in a 'sub-window' of this page. (This should work in most GUI web browsers.)

You can save a code sample locally by using a right-click and choosing an option such as 'This Frame > Show Only This Frame' in the popup menu (of your web browser) that appears.

Then, when the code is shown in a separate window, right-click and choose 'Save Page As ...' in the popup menu that appears.

    NOTE:
    Using this technique of putting the code samples on the page with HTML 'object' tags is not the most efficient way of showing the code samples. It can take quite a few seconds for all the code samples to load into the browser window.

    However, one advantage is that you can do a 'Find text' operation with a web browser and it will find ALL the occurrences of the text string in ALL the code samples.

    That said, I may revise this page someday so that it loads faster --- especially if more code samples are to be supplied by this one page.


NAVIGATION :

Use the table-of-contents (above) to go directly to the display of a code sample-group of interest. OR simply scroll down this page to spot samples of interest.

Alternatively:
Use a 'Find text' option of your web browser to look for keywords on this page. For example, when looking for examples of code that demonstrate GUI programming with GLUT, GLUI, FLTK, GTK, Qt, or wxWidgets routines, use keywords like 'glut' or 'menu' or 'glui' or 'fltk' or 'gtk' or 'qt' or 'wx'.

When looking for code 'snippets' involving an OpenGL Vertex command or an event handling loop, use 'vertex' or 'loop' or 'run()'.

When looking for code 'snippets' involving OpenGL shaders or light sources or motion blur or buffers or stencil, use keywords like 'shade' or 'phong' or 'light' or 'blur' or 'buffer' or 'stencil'.

When looking for code 'snippets' involving splines or NURBs or heightfields, use keywords like 'spline' or 'nurb' or 'surface' or 'height' or 'field'.

When looking for code 'snippets' involving geometric 'primitives' like cubes or spheres or tori or teapots, use keywords like 'cube' or 'sphere' or 'torus' or 'teapot' or 'rectangle' or 'circle'.

When looking for code 'snippets' involving reading or writing 3D files of a certain type, like DXF or DWG or OBJ or LW or POV or VRML, use keywords like 'dxf' or 'dwg' or 'obj' or 'lw' or 'pov' or 'vrml' or 'read' or 'write'.

When looking for code 'snippets' involving reading or writing 2D files of a certain type, like TARGA or BMP or AVI, use keywords like 'targa' or 'bmp' or 'avi'.


FINDING MORE SAMPLES, ON THE INTERNET :

One way to look for code samples is to do a Google search on filetype:c or filetype:cpp.

You can add additional search terms, such as 'opengl' and/or 'glui' and/or 'gtk'.

---

If you do not like the way Google records everything you do, you could use a web searcher, like DuckDuckGo, that has more respect for your desire to avoid running a gauntlet of ads every time you use an app or web site that uses Google utilities.

So you could do searches using keywords like the following.

Start of the C Code Samples :

Start of 'ogl-skel' C programs
(OpenGL programs that are 'skeletons' --- templates for your programs)


FILE - ./src_c/ogl-skel-NOmenu_Main_template_ww2-cs-mu-oz-au_13kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-NoKMctl' C programs
(OpenGL programs with NO keyboard, mouse, or GUI controls)


FILE - ./src_c/ogl-NoKMctl_viewer_labri-fr_3kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-NoKMctl_gldemo_sphere_cs-csubak-eduSTmarc_5kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-NoKMctl_lissajous_opengl_people-sc-fsu-eduSTjburkardt_6kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-NoKMctl_spots_kilgard_opengl-org_9kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-NoKMctl_scene_people-rit-edu_11kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-keyctl' C programs
(OpenGL programs with keyboard control --- BUT NO mouse or GUI controls)


FILE - ./src_c/ogl-keyesc_ass1_houseAndTree_alumni-cs-ucr-eduSTmvlachos_7kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_colorcubes_webs-wofford-edu_7kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl-anim-light_SimpleLight_math-ucsd-edu_7kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_cubemap_zach-in-tuHclausthal-de_8kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_blancmange_mathSurface_trajectorylabs-com_10kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_WrapTorus_buss_math-ucsd-edu_11kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_paramsurf_cs-csustan-edu_13kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_texenv_Kilgard_csee-umbc-edu_19kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl-fort_bottles_spyHhill-com_21kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-keyctl_blackhole_linuxdevcenter-com_26kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-M' C programs
(OpenGL programs with Mouse control --- BUT NO keyboard or GUI controls)


FILE - ./src_c/ogl-Mexit_glimage_sinSurface_fab-cba-mit-edu_1kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-KMctl' C programs
(OpenGL programs with keyboard AND mouse controls --- BUT NO GUI controls)


FILE - ./src_c/ogl-KMctl_bounce_tom-cs-byu-edu_5kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-KMctl_circles_spyHhill-com_6kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-KMctl_splines_artis-imag-fr_6kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-KMctl_heightfield_cs-cmu-edu_8kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-KMctl_mesh_shader_angel_cs-unm-edu_8kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-KMctl_Tetris_pages-cs-wisc-edu_78kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-gmenu' C programs
(OpenGL programs with GLUT menus --- i.e. some GUI controls)


FILE - ./src_c/ogl-gmenu_events_bhecker-com_8kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gmenu_glut_example_cs-texas-edu_8kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gmenu_explosion_student-nada-kth-se_10kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gmenu_Mandelbrot_community-middlebury-eduSTyaok_12kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gmenu-stencil_decal_eng-utah-edu_13kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gmenu_worms_opengl-org_14kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of 'ogl-gtk' C programs
(OpenGL programs with GTK GUI controls)


FILE - ./src_c/ogl-gtk_gl_www710-univHlyon1-frSTexco_13kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_disp3d_svn-savannah-gnu-org_14kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_final1_www-cs-clemson-edu_14kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_ostreni_stelweb-asu-cas-cz_16kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_logo_imac-unavarra-es_20kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_coolwave_imac-unavarra-es_20kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_sample_gtkgl2_simgw-cosmos-ehimeHu-ac-jp_23kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_zktor_dca-fee-unicamp-brSTting_24kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil-ogl-gtk_motionblur_behdad-org_25kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_preview3d_gimpHnormalmap-googlecode-com_48kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/ogl-gtk_callback_cosmix_nbodysim_cosmix-project-free-fr_82kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of '3Dfil' C programs
(programs that read or write 3D files --- DXF, OBJ, or whatever
--- with or without OpenGL calls)


FILE - ./src_c/3Dfil-ogl_smvr_readObj_pages-cs-wisc-edu_18kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil_DXFConv_dxf2dkb_users-polytech-unice-fr_20kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil-ogl-gtk_viewlw_readLW_andrewd-ces-clemson-edu_12kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil_cad2svg_readDWG-DXF_etc-nkadesign-com_39kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil_exotic_readIV_download-blender-org_43kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.

FILE - ./src_c/3Dfil_lparser_writeDXF-POV-VRML1_markjstock-org_100kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of '2Dfil' C programs
(programs that read or write 2D files --- image or video ---
Targa, AVI, or whatever ---with or without OpenGL calls)


FILE - ./src_c/2Dfil-ogl-keyctl_glut_capture_2avi_2bmp_tecgraf-pucHrio-br_11kb.c :

< Go to Table of Contents, above. >

See comments in the code :

File is not shown. Technical difficulties.


Start of C++ code samples :

Bottom of this
Programming Code Samples page
--- especially C, GUI's, and 3D (OpenGL) code samples.

To return to a previously visited web page location, click on the Back button of your web browser, a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to start of
C programs display, above. >


< Go to start of
C++ programs display, above. >


< Go to start of
Table of Contents, above. >


< Go to Top of Page, above. >

Page history

Page was created 2011 Feb 09.

Page was changed 2011 Jun 06.

Page was changed 2019 Mar 12.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)